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.
| Author |
Topic |
|
Ravi0435
Starting Member
47 Posts |
Posted - 2011-08-22 : 18:40:47
|
| Hi..Why doesnt this work? why does it not take the seed value from a variable? i Dont understand thew error.Declare @seed_2 bigintSet @seed_2 = 1070001000000008136Alter Table GROUPEDFORPKAdd AssignedHeaderPK bigint identity(@seed_2,1) Error: Says Msg 102, Level 15, State 1, Line 5Incorrect syntax near '@seed_2'Thanks,RaviNothing much that i can do..!! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Ravi0435
Starting Member
47 Posts |
Posted - 2011-08-22 : 18:57:21
|
| Thanks for the reply/suggestion.I tried that as well and the following doesnt work either and says - incorrect syntax near @Database.set @sql = 'USE ' + @Database + 'Alter Table RAW_CLAIM_GROUPEDFORPKAdd AssignedHeaderPK bigint identity('+cast((Select (MAX(AssignedHeaderPK)+1) From '+ @Database'+.dbo.RAW) as bigint)+',1)'--print @sqlexec (@sql) Nothing much that i can do..!! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Ravi0435
Starting Member
47 Posts |
Posted - 2011-08-22 : 19:11:49
|
| No it did not work...asssume that i need to re-write the first one in to Dynamic SQL how would you write it?The first code when i write it in Dynamic SQL = second code.the reason it looks complicated is because instead of temp variable i substituted the whole SQL statement, let me put it this way below might be easier.set @sql = 'USE ' + @Database + 'Alter Table RAW_CLAIM_GROUPEDFORPKAdd AssignedHeaderPK bigint identity('+cast(@seed_2) as bigint)+',1)'and we have @Database = HCN@seed_2 = Select (MAX(AssignedHeaderPK)+1) From HCN.dbo.RAW Nothing much that i can do..!! |
 |
|
|
Ravi0435
Starting Member
47 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2011-08-22 : 20:33:56
|
| You can't nest your query in there like that.Let's start with the simple example:Declare @seed_2 bigintSet @seed_2 = 1070001000000008136Alter Table GROUPEDFORPKAdd AssignedHeaderPK bigint identity(@seed_2,1) And now let's rewrite it:Declare @seed_2 bigint, @sql nvarchar(4000)Set @seed_2 = 1070001000000008136set @sql = 'Alter Table GROUPEDFORPK Add AssignedHeaderPK bigint identity(' + convert(varchar(20), @seed_2) + ',1)'exec @sqlDoes that work?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2011-08-23 : 02:32:42
|
Can you useDBCC CHECKIDENT ('GROUPEDFORPK', RESEED, 1070001000000008136)after adding the column, or do you need it to assign IDs to existing records starting from that number?(Probably the later, in which case this won't help ) |
 |
|
|
|
|
|
|
|