?
Solved

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

Posted on 2012-03-20
3
Medium Priority
?
278 Views
Last Modified: 2012-03-20
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
0
Comment
Question by:tbaseflug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 37743034
doesn't this work:

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

Open in new window

0
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 37743040
SET @startIndex = (@startIndex - 1) * 1000
0
 

Author Closing Comment

by:tbaseflug
ID: 37743053
It sure does... Whoops...  Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question