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 |
magmo
Aged Yak Warrior
558 Posts |
Posted - 2013-04-08 : 03:14:06
|
HiI have the following stored procedure query...SELECT TOP (@TopItems) PdfFileName, ID, IsFetchedFROM dbo.CardsWHERE (IsFetched IS NULL OR IsFetched = 0) AND (PdfFileName <> N'')ORDER BY DateAdded I would like to change this so that if I pass @TopItems = 0 then I should retrieve all rows (not using the TOP xx part), but if I pass any value higher than 0, the TOP part should be used, how can I change this? |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-08 : 05:20:25
|
[code]DECLARE @TopItems INT =0IF ( @TopItems > 0)BEGIN SELECT TOP (@TopItems) PdfFileName, ID, IsFetched FROM dbo.Cards WHERE (IsFetched IS NULL OR IsFetched = 0) AND (PdfFileName <> N'') ORDER BY DateAddedEND ELSE BEGIN SELECT PdfFileName, ID, IsFetched FROM dbo.Cards WHERE (IsFetched IS NULL OR IsFetched = 0) AND (PdfFileName <> N'') ORDER BY DateAddedEND [/code] |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2013-04-08 : 05:38:10
|
Thank you very much, that works great! |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-08 : 06:10:58
|
quote: Originally posted by magmo Thank you very much, that works great!
Welcome--Chandu |
|
|
|
|
|