vendredi 26 novembre 2021

Set where clause basis parameter value in SQL Server

I wish to set a condition while making use of the WHERE clause basis @USER_ID input recorded from the user in my SQL server query, but I guess I am missing something essential here.

DECLARE @USER_ID NVARCHAR(255) = 'a,b,c' -- will be multi-select parameter; can be null as well 


select * from <table_name>

{
if:      @USER_ID is NULL then no WHERE condition
else:    WHERE <table_name>.<col_name> in (SELECT item FROM SplitString(@USER_ID,','))
}

Can someone please help here?

Aucun commentaire:

Enregistrer un commentaire