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 |
|
aoriju
Posting Yak Master
156 Posts |
Posted - 2011-04-20 : 08:27:36
|
| DECLARE @str VARCHAR(100);SET @str ='SR'IF @str ='SR' THEN i want getSELECT TOP 10 COL FROM TBLELSESELECT * FROM TBLI am looking a Query with out IF and Dynamic Query |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-04-20 : 08:34:27
|
[code]DECLARE @str VARCHAR(100);SET @str ='SR'IF @str ='SR' THEN i want getSELECT TOP 10 COL FROM TBLELSESELECT * FROM TBL[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
aoriju
Posting Yak Master
156 Posts |
Posted - 2011-04-20 : 08:43:07
|
| Hai...I don't like to use IF And ELSE statement....Is any other way to write this ? |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2011-04-20 : 09:09:09
|
No. You asked for two different queries - different conditions and different column lists. Why would you expect to combine them with 1 statement?Corey I Has Returned!! |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-04-20 : 09:11:10
|
what version of SQL Server are you using ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
aoriju
Posting Yak Master
156 Posts |
Posted - 2011-04-21 : 00:32:06
|
| SQL 2008 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-04-21 : 00:45:46
|
[code]DECLARE @str VARCHAR(100);SET @str ='SR'; with tbl as( select *, row_no = row_number() over (order by [somecol]) from [yourtable])select *from tblwhere @str <> 'SR'or (@str = 'SR' and row_no <= 10)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
aoriju
Posting Yak Master
156 Posts |
Posted - 2011-04-21 : 01:05:24
|
| Thanks very much |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|