Can you not raise errors within a case statement in T-SQL? I always have problems with SQL case statements :/
begin try
declare @i int
--set @i = (select COUNT(1) from table_name)
select Item_Num =
CASE (select COUNT(1) from table_name)
when 1 then (select Item_Num from table_name)
when 0 then (raiserror('No records in database', 0, 0))
ELSE (raiserror('Multiple records in database', 0, 0))
END
from table_name
end try
begin catch
declare @errormsg nvarchar(1024),
@severity int,
@errorstate int;
select @errormsg = error_message(),
@severity = error_severity(),
@errorstate = error_state();
raiserror(@errormsg, @severity, @errorstate);
end catch
CASE
statement. Then callRAISERROR
or theSELECT
statements depending on the value of this flag... – Faline