Solved

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

Posted on 2012-03-20
3
274 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
3 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

803 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