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)
 Return top row if no data is returned?

Author  Topic 

Goalie35
Yak Posting Veteran

81 Posts

Posted - 2009-06-22 : 00:51:18
I have a query that returns a bunch of user info but when you have a user who hasn't entered any data yet, the query obviouly returns no results.

I need to setup a query so that if the query returns no results, I then simply return the top record in the database.

Any idea how I can set this up?

Thanks.

doran_doran
Posting Yak Master

179 Posts

Posted - 2009-06-22 : 01:03:51
if exists (select * from someTable where field = something)
- do something
else
select top 10 from sometable
end
Go to Top of Page

Goalie35
Yak Posting Veteran

81 Posts

Posted - 2009-06-22 : 01:13:36
Thanks doran_doran, that did it!
Go to Top of Page

doran_doran
Posting Yak Master

179 Posts

Posted - 2009-06-22 : 01:55:23
I am glad I could help. Good luck with your project.
Go to Top of Page
   

- Advertisement -