Set param - dynamic- better way to write what I have

Is there a more "elegant" way to write the below - perhaps some simple loop to make it more "dynamic" so I dont have to iterate through every number - say up to 10000, etc.?

DECLARE @startIndex int, @pageSize int
SET @startIndex = 2

SET @startIndex =
CASE
WHEN @startIndex = 1 THEN 0
WHEN @startIndex = 2 THEN 1000
WHEN @startIndex = 3 THEN 2000
WHEN @startIndex = 4 THEN 3000
WHEN @startIndex = 5 THEN 4000
WHEN @startIndex = 6 THEN 5000
WHEN @startIndex = 7 THEN 6000
WHEN @startIndex = 8 THEN 7000
END
tbaseflugAsked:
Who is Participating?
 
Robert SchuttSoftware EngineerCommented:
doesn't this work:

SET @startIndex = 1000 * (@startIndex - 1)

Open in new window

0
 
Barry CunneyCommented:
SET @startIndex = (@startIndex - 1) * 1000
0
 
tbaseflugAuthor Commented:
It sure does... Whoops...  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.