Quantcast
Channel: PTC Community: Message List - Windchill
Viewing all articles
Browse latest Browse all 8876

Re: Create 99 sequences in MS SQL

$
0
0

I think this will work if you first store the CREATE TABLE and CREATE PROCEDURE commands as string variables, and then run EXEC on those variables. Try something like the below:

 

DECLARE @intFlag INT,@table nvarchar(300), @createTable nvarchar(300),@proc nvarchar(300), @createProc nvarchar(300)

 

SET @intFlag = 1

 

WHILE (@intFlag <= 99)

 

BEGIN

    SET @table = 'wt_sequence_KOIID_' + cast(@intFlag as nvarchar) + '_seq'

    SET @createTable = 'CREATE TABLE ' + @table + '(dummy CHAR(1), value BIGINT IDENTITY(1,1))'

    EXEC(@createTable)

 

   

    SET @proc = 'wt_get_next_sequence_KOIID_' + cast(@intFlag as nvarchar) + '_seq'

    SET @createProc = 'CREATE PROCEDURE ' + @proc + '(@returnValue BIGINT OUTPUT)

 

    AS

 

    INSERT ' + @table + ' (dummy) VALUES (''x'')

 

    SELECT @returnValue = SCOPE_IDENTITY()'

 

    EXEC(@createProc)

 

    SET @intFlag = @intFlag + 1

   

   

END

 

go


Viewing all articles
Browse latest Browse all 8876

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>