Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Insert statement

Author  Topic 

abenitez77
Yak Posting Veteran

53 Posts

Posted - 2011-10-25 : 16:37:01
I want to replace the 1 in my insert statement, that I am inserting into TableIndex column with an incrementing number starting with 1. The number will depend on the number of items in my string below for @TableNameDetail. In this case it will go from 1 to 3, so I am inserting 3 records and Table1 will have TableIndex = 1, Table2 will have TableIndex = 2, Table3 will have TableIndex = 3.

set @TableNameDetail = 'table1,table2,table3'


Insert Into [tblTables](TableName, TableIndex, SQLAuth)
Output Inserted.TableID, Inserted.TableName Into @MyTableVar
Select Item, 1, 0 From PRGX_AS_UTILITY.dbo.DelimitedSplit8k(@TableNameDetail,',') as T WHERE T.Item
Not IN (Select Tablename From tblTables)

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-10-25 : 16:50:34
You could either modify your DelimitedSplit8K function to return an identity and use that or you could use a row_number() function.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -