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 2008 Forums
 Transact-SQL (2008)
 IF clause in Stored Proc

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2014-04-30 : 15:27:17
I need to do something like the following within a stored proc

c = SELECT count(jobid)
FROM tblJobs
WHERE JobStatusId IN (2,3,6,7)

if (c > 0)
{
// DO THIS
}

Could anyone help me with the syntax?

Many Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-04-30 : 15:34:10
if exists (SELECT * FROM tblJobs WHERE JobStatusId IN (2,3,6,7))
begin
...
end

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -