August 10, 2006 at 11:41 am
I know this is probably a dumb question, but I can't figure out how to do this.
I want to set up a job step and with that step I want to count the rows in a table, if there are more than 0 then I want the step to error out. If there are 0 rows in the table I want the job step to finish successfully. Can someone help? This is where I can't figure out how to make it generate an error:
declare @count int
select @count = count(*) from test_tbl
IF @count > 0
begin
print 'This is bad'
end
else
begin
print 'Good to go'
END
Thanks!
August 10, 2006 at 12:18 pm
You should make use of the RAISERROR method. Read about it in Books Online.
N 56°04'39.16"
E 12°55'05.25"
August 10, 2006 at 12:18 pm
Use Raiserror. Use with log if you want the error to appear in the log file.
select @count = count(*) from test_tbl
IF @count > 0
raiserror('Your Error Message Here',16,1) with log
else
print 'Good to go'
August 10, 2006 at 3:10 pm
probably obvious to everyone that you can avoid the variable and just us an if exists:
IF exists(select * from test_tbl)
raiserror('Your Error Message Here',16,1) with log
else
print 'Good to go'
this is my 501st. post on SSC. woot!
Lowell
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply