Solved

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

Posted on 2012-03-20
3
269 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now