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

IF STATEMENT ON A SELECT?

Status
Not open for further replies.

JONBOY74

Technical User
Sep 11, 2001
36
US
Hi all

Can you use IF statements with select statements so that, a error messege appears in place of the selected data if that data doesn't exist.

Any help or pointer please

Jon
 
Yes you can user IF statements i.e.

If (select count(*) from call_type) = 0
print 'No records returned'
else
print 'There are records'


Rick.
 
If you're talking about T-SQL in a stored procedure thenyou can use the builtin @@rowcount variable:

select ... from ... where
if @@rowcount=0
begin
print "No Records Matched"
return
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top