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 2000 Forums
 Transact-SQL (2000)
 Stored Procedure, Loops

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 int
set @var = @param - 1 -- @param is the parameter passed

Update Table
Set @var = SomeID = @var + 1

Select * from Table[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

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_addIDs
2. @nextValue int, --starting number @param.
3. @length int --I need to assign id's to the first 15 rows only.
4. AS
5. declare @val int
6. begin
7. @val = 1 --Auto number column will have this value
8. while @val <= @length
9. begin
10. update table1 set Bookid=@nextValue where serialId=@val
11. @val = @val + 1
12. end
13. end
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -