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 |
vinay.a
Starting Member
20 Posts |
Posted - 2008-04-24 : 06:21:44
|
hi,I am using asp.net and sql server 2005 for my project.I need to pass a number(SomeId) into the stored procedure and add that number to the 'SomeId' column in the form of incrementation of 1 to each row.The table may have many rows, let's say 35 rows. If the number passed is , let's say 201, then the first row should get the value '201', the second-202, third-203, and so on.Can someone help me with this.If the looping is not possible, please suggest that does the same.regards,vinay |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-04-24 : 06:46:14
|
[code]Declare @var intset @var = @param - 1 -- @param is the parameter passedUpdate TableSet @var = SomeID = @var + 1Select * from Table[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
vinay.a
Starting Member
20 Posts |
Posted - 2008-04-24 : 07:44:47
|
hi,I was trying something else, I have an 'id' column which is generating auto numbers from 1.I have another column - 'SomeId' into which I am adding the id's starting from the number that I pass in. In your code the passing value is captured by @param.Please review the code below and let me know the errors.I have errors in line 7,11. (Incorrect syntax near '@val')1. Create procedure usp_addIDs2. @nextValue int, --starting number @param.3. @length int --I need to assign id's to the first 15 rows only.4. AS5. declare @val int6. begin7. @val = 1 --Auto number column will have this value8. while @val <= @length9. begin10. update table1 set Bookid=@nextValue where serialId=@val11. @val = @val + 112. end13. end |
 |
|
vinay.a
Starting Member
20 Posts |
Posted - 2008-04-24 : 08:12:08
|
hi Harsh,The code u provided, I worked on it and it is working fine.Can I send an array list of id's (string variable) which are not in sequence and are randomly generated by my application.I will be sending the array with length as required to update the rows in the table. |
 |
|
|
|
|
|
|