?
Solved

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

Posted on 2012-03-20
3
Medium Priority
?
284 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 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

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

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

Ready to get certified? Check out some courses that help you prepare for third-party exams.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Suggested Courses

850 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