sql - How to use IF Else in store procedure? -
i trying execute select query id parameter, if id empty want rows, otherwise row contains id, far, have created store procedure,
if(@custid = null) begin select * tblcustomer end else begin select * tblcustomer custid=@custid end
when executing query id, getting result when passing, not getting result. what's correct way this?
null handled differently other values, need use
if (@custid null)
your current code of if(@custid = null)
evaluate false, else case executed regardless of pass @custid
. this article goes more detail how handle null values:
Comments
Post a Comment