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)
 Query to return empty table only?

Author  Topic 

dhw
Constraint Violating Yak Guru

332 Posts

Posted - 2002-12-23 : 17:07:33
Does anyone know if there is a simple SQL query that I can use to return an empty table? I have a large quantity of tables that I want to return an empty result for....at the moment I am adding a WHERE clause to my sql expression that is specific to each table...and providing a column/value comparison that will return zero records. I was wondering though, if there were a simple or generic t-sql statement or option that I could add to my sql statement to provide the same results - an empty dataset.

thanks...

jasper_smith
SQL Server MVP & SQLTeam MVY

846 Posts

Posted - 2002-12-23 : 17:29:21

select * from blah
where 1=0

or


set FMTONLY ON
select * from blah
set FMTONLY OFF



HTH
Jasper Smith

Edited by - jasper_smith on 12/23/2002 17:35:21
Go to Top of Page

dhw
Constraint Violating Yak Guru

332 Posts

Posted - 2002-12-23 : 17:53:04
thanks!! both of these solutions will work for me.

..

Go to Top of Page

fire1
Starting Member

5 Posts

Posted - 2002-12-26 : 08:08:23
u can also use:

select top 0 * from table

Go to Top of Page
   

- Advertisement -