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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 single select statement

Author  Topic 

ranganath
Posting Yak Master

209 Posts

Posted - 2008-03-01 : 01:38:31
Hi,

i have an input parameter @PageloadYN Bit Null

if @PageloadYN = 1 then Select top 500 Records from the Table
if @PageloadYN = 0 then Select * from the Table

i tried like this

Select top 500.* From Table where @PageloadYN = 1
Select * From Table where @PageloadYN = 0


Is there any way to get details in Single select statement only.

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2008-03-01 : 02:14:17
You can do it in a single SELECT statement but in a different way..

If @PageloadYN = 1
SET ROWCOUNT 500
ELSE
SET ROWCOUNT 0

SELECT * FROM Table



Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-03-01 : 02:30:18
this works too (in 2005)

select top(case when @PageloadYN=1 then 500 else 5000000 end) * from mytable


elsasoft.org
Go to Top of Page
   

- Advertisement -