We have a scenario, suppose we have a table like below
CREATETABLEEMP ( FNAMEVARCHAR(100) ,LNAMEVARCHAR(100) ,CREATEDDATEDATETIME, ) INSERTINTOEMP SELECT'DILIP','SINGH',GETDATE() UNIONALL SELECT'ANIL','SINGH',GETDATE() UNIONALL SELECT'ASHISH','PRATAP',GETDATE() |
See following SQL statements
DECLARE@myNameVARCHAR(20)='ANIL' SELECTFNAMELNAMEFROMEMP WHEREFNAME= @myName |
Here @myName parameter is declared and condition are if @myName =Null then return all records otherwise return related records.
Please see following query which can resolve this problem
DECLARE@myNameVARCHAR(20)=NUll SELECTFNAMELNAMEFROMEMP WHEREFNAME=ISNULL(@myName,FNAME) |
Clik here to view.
