in SQL Server , how do I verify if a query has returned NULL and run blocks depending on it . e.g. in query 1 , I want to check if count(*) is not null and then check if it has >0 . Should I use if exists here ?
if select count(*) from tbl1 not is NULL then
if select count(*) from tbl1 where count(*)>0 then
raiserror()
end if
end if
In Oracle one can say IF INSERTING THEN or IF updating THEN or if deleting then run a certain block of code based on a column . how do we do it in SQL Server ? Please see Oracle code below .
CREATE OR REPLACE TRIGGER tr_name
BEFORE DELETE OR INSERT OR UPDATE OF column1 ON tbl1
FOR EACH ROW
WHEN (NEW.column1 IS NOT NULL)
begin
IF INSERTING THEN
run some code like check if there are more than row in a table and if >0 then not allow any inserts
IF updating THEN
run some code
IF deleting THEN
run some code
end
COUNTnever returnsNULL.ISNULL, because I don't think it does what you think it does, given yourISNULL(...) > 0example in that comment.