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 2000 Forums
 Transact-SQL (2000)
 Returning No Results

Author  Topic 

Billkamm
Posting Yak Master

124 Posts

Posted - 2006-02-16 : 16:21:59
I need to return a table that contains no results (0 rows)

I tried doing SELECT NULL; but that returned 1 row, because NULL is in a row.

I was going to do something like SELECT NULL FROM table WHERE 1 = 2;

But I'm sure there has to be a better way.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-16 : 16:23:14
WHERE 1=2 is the best way.

Tara Kizer
aka tduggan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-17 : 08:26:36
Also you dont need to use Null. It can be numbers also

SELECT 1 FROM table WHERE 1 = 2




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

dsdeming

479 Posts

Posted - 2006-02-17 : 10:20:39
If you want to return an empty recordset with the same structure as your table, don't use SELECT 1 FROM table WHERE 1 = 2. It returns a recordset with 1 unnamed column. Instead use SELECT * FROM table WHERE 1 = 2.

Dennis
Go to Top of Page
   

- Advertisement -