<@UHBRA5CGH> You got some 'splainin' to do! This i...
# sql
i
@Scott Stroz You got some 'splainin' to do! This is in MySQL • I have two tables,
x
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.
Copy code
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
.
Copy code
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
.
Copy code
on x.cpt_code = cast(y.cpt_code_id as nchar)
For example:
Copy code
select CAST('76830,76856' as UNSIGNED) as id;
Returns 76830