sql server - Building SQL Query with NULL check -
this question has answer here:
- apply conditional filtering in clause 2 answers
i writing stored procedure in sql server 2014 , given below
create procedure [dbo].[getusers] @role int select firstname, lastname users firstname = 'something' if nullif(@role, '') not null begin , role = @role end end
with throwing syntax error @ and
i want build query dynamically , exclude null
, ''
values
you can't build dynamic query that. can use boolean logic
select firstname, lastname users firstname = 'something' , (@role null or @role = '' or role = @role)
Comments
Post a Comment