iknowkungfoo
01/28/2023, 6:01 AMx
and y
.
• x.cpt_code
is nvarchar(255)
• y.cpt_code_id
is an int.
• x.cpt_code
can have a comma delimited list of numbers
• I need to join the two tables on the numeric value of the int
.
Figured that if I cast the string to an int
, then the list would wash out. Not the case.
x on cast(x.cpt_code as unsigned) = y.cpt_code_id
matches a single number a
to a list of numbers where the first element is a
.
x on x.cpt_code = y.cpt_code_id
does the exact same thing.
However, if I cast the int
to nchar
, the string matches only when string is the exact numeric value of the int
.
on x.cpt_code = cast(y.cpt_code_id as nchar)
For example:
select CAST('76830,76856' as UNSIGNED) as id;
Returns 76830