Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 hi all case help

Author  Topic 

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-05 : 08:00:43
hi all,
i want to print numbers from 40 to 50

i executed following query

declare @start int
set @start=40
declare @endv int
set @endv=50
declare @diff int
set @diff=@endv-@start
select case when @diff > 0
then
@start= @start+1
@diff =@diff-1
select @start
end

but comes with an error

can u pls help
thanks in advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-05 : 08:02:44
you cant use case like this. what you want is if

declare @start int
set @start=40
declare @endv int
set @endv=50
declare @diff int
set @diff=@endv-@start
if @diff > 0
select @start= @start+1,
@diff =@diff-1
select @start
end
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-05 : 08:08:45
hi
it comes with an error


Incorrect syntax near the keyword 'end'

can u help me once more
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-05 : 08:10:09
remove it. i forgot to remove it.
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-05 : 08:11:45
ok
thanks visakh..

can we implement above using case when structure

Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-05 : 08:13:08
hi
its not working after removing end

it only gives 41 as result

help me
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-05 : 08:19:46
hi phumzille ,

pls post ur table with sample data
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-11-05 : 08:55:03
What's this forum post about now?

Is it about soorajtnpki's question or Phumzile's one?????

Phumzile -- if this is completely unrelated can you please make a new post rather than hijack this one?

--------------------

Soorajtnpki -- Is this what you were looking for (it's exactly what you asked for)


DECLARE
@start INT
, @endv INT
, @counter INT

SELECT @start = 40, @endv = 50
SELECT @counter = @start

WHILE ( @counter <= @endv ) BEGIN
PRINT @counter
SET @counter = @counter + 1
END


===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-06 : 02:10:28
thanks

it works..
very thanks.......
Go to Top of Page
   

- Advertisement -