sql server - Building SQL Query with NULL check -


this question has answer here:

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

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -