Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Loop for several values
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01327001
Message ID:
01327003
Views:
12
This message has been marked as the solution to the initial question of the thread.
>Hi everybody,
>
>Suppose I have several PersonIDs I'd like to test my SP with. How can I create a loop to do it?
>
>Thanks in advance, though I do have an idea myself.
DECLARE @Test TABLE (PersonId int /*or whatever*/, ID Int IDENTITY(1,1))
INSERT INTO @Test (PersonId) VALUES (??)
INSERT INTO @Test (PersonId) VALUES (??)
INSERT INTO @Test (PersonId) VALUES (??)
INSERT INTO @Test (PersonId) VALUES (??)
INSERT INTO @Test (PersonId) VALUES (??)
INSERT INTO @Test (PersonId) VALUES (??)

DECLARE @PersonId      int -- or whatever
DECLARE @id_min        int
DECLARE @id_max        int
SET @id_min = 1
SELECT @id_max = MIN(Id) FROM @Test

WHILE @id_min <= @id_max
      BEGIN
         SELECT @PersonId = PersonId FROM @Test WHERE Id = @id_min
         --- Test your SP here
         SET  @id_min =  @id_min + 1
      END
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform