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.
| 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 50i executed following querydeclare @start intset @start=40declare @endv intset @endv=50declare @diff intset @diff=@endv-@startselect case when @diff > 0 then @start= @start+1 @diff =@diff-1 select @start endbut comes with an errorcan u pls helpthanks 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 ifdeclare @start intset @start=40declare @endv intset @endv=50declare @diff intset @diff=@endv-@startif @diff > 0select @start= @start+1,@diff =@diff-1select @startend |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-11-05 : 08:08:45
|
| hi it comes with an errorIncorrect syntax near the keyword 'end'can u help me once more |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-05 : 08:10:09
|
| remove it. i forgot to remove it. |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-11-05 : 08:11:45
|
| okthanks visakh..can we implement above using case when structure |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-11-05 : 08:13:08
|
| hi its not working after removing endit only gives 41 as resulthelp me |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-11-05 : 08:19:46
|
| hi phumzille , pls post ur table with sample data |
 |
|
|
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 INTSELECT @start = 40, @endv = 50SELECT @counter = @startWHILE ( @counter <= @endv ) BEGIN PRINT @counter SET @counter = @counter + 1END ===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-11-06 : 02:10:28
|
| thanks it works.. very thanks....... |
 |
|
|
|
|
|