Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I check if query return 0 records

Status
Not open for further replies.

gcole

Programmer
Aug 2, 2000
390
US
I need a statement that will return a 0 result from a query. I tried:
If Exists( select * from out_product
where productname not in
(select product from out_listownership))

but it doesn't return a false.
 
Are you trying to do this in T-SQL or another programming language?

Jack
 
I don't think we are clear on what you want, but you can try this to see if it close to what you are thinking. If not, perhaps try to describe a bit more what you are aiming at.
[tt]
Select (select count(*) from out_product
where productname not in
(select product from out_listownership)
) as TheCount
[/tt]

------------
bperry
 
When I re-read, I see you want to check if it is zero. Perhaps you mean something like this inside a stored procedure or script?

[tt]
declare @mycount int
select @mycount = (Select (select count(*)
from out_product
where productname not in
(select product from out_listownership))
if @mycount = 0
do this
else
do that
-------------------
[/tt]
 
Try this.

If Exists
(Select *
From out_product a
Join out_listownership b
On a.productname = b.product) Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top