aggicd
aggicd

Reputation: 737

SQL Server: check if string contains numbers (single or double digits)

I have a stored procedure and I want to pass a string parameter which contains numbers representing the steps that need to be executed.

For example:

dc.SProcCP("1,2,14,24") //steps 1, 2, 14 and 24 need to be executed

In my stored procedure, I have a set of ifs . Each one checks if the input argument contains a step. Like in the first if :

if (CHARINDEX("1",@inputsteps)>0 ....

But this will be true if steps contain "1" or if steps contain "14".

How I can solve this?

Upvotes: 1

Views: 475

Answers (1)

DhruvJoshi
DhruvJoshi

Reputation: 17146

you can simply check like below

if (CHARINDEX('1,',CONCAT(@inputsteps,','))>0 ....

Upvotes: 1

Related Questions