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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IT'S POSSIBLE TO KNOW WHEN A SELECT IS EMPTY ????? 2

Status
Not open for further replies.

ivoestg

Programmer
Mar 21, 2001
77
0
0
PT
hi,
can you tell me if it's possible to know when a result of a select is empty???
i need to do something like that:

if (select id from ppl where id =3) not null then
<code to make>
end if
thanks...

I'm in ivoestg@yahoo.com
 
What's your platform, and what's your purpose. We don't read minds here. AA 8~)
 
with ansi sql, i think you can say

select count(*)
from (select id from ppl where id =3)

if your database doesn't support that, perhaps try the appropriate forum for your database

rudy
 
If you are using MS SQL Server and you are in a stored procedure the system variable @@ROWCOUNT could be the ticket. For example-
Code:
SELECT *
FROM customers WHERE 1=2

IF @@ROWCOUNT = 0
BEGIN
SELECT 'None Found'
END

But you see it all depends on which DBMS you are using.

I wonder, is there an ANSI standard for this?
 
If you're writing a stored procedure you can use:
Code:
if Exists (select id from ppl where id =3) 
  ...some code...
else
  ...some other code...

Or you can use:
Code:
select  * from someTable where Exists (select id from ppl where id =3)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top