Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Search for a value in a numeric variable list

By ronenr,

When you have a variable that hold a comma separated numbers like '1,2,3' and you have a table with a column that has the value that should match a number in that list, you can use this script to avoid building a string and then executing it.

You have to convert the columnID to varchar, the size of the varchar must be the biggest size that the number can have, for example if ColumnID range from 0 to 9999, the varchar will be varchar(4).

The list MUST NOT have spaceses between the numbers, if so, the script will not work.

Total article views: 357 | Views in the last 30 days: 1
 
Related Articles
FORUM

varchar issue

varchar issue

FORUM

Difference between varchar(max) and varchar(8000)

Difference between varchar(max) and varchar(8000)

FORUM

VARCHAR(x) VS VARCHAR(MAX)

any downside to VARCHAR(MAX)?

FORUM

Regarding using VARCHAR(MAX)

Usage of VARCHAR(MAX)

FORUM

convert varchar to numeric

convert varchar to numeric

Tags
miscellaneous    
t-sql    
 
Contribute