sql - Joining with a column of type varchar that has both string and numbers stored in it -
i have column in table of type varchar(50)
stores both words , ids. example there values such as: 50, 95, example, testing....
when not isnumeric(column)
, can use value. when isnumeric(column)
, need join table value supposed selected.
i got select
part down:
select case when isnumeric(column) = 1 othertable.name else column end
now trying join
under same scenario:
left join othertable ot on cast(column int) = t.id
this not work because cast
not work when column word. need join if column number.
i not fan of using 1 column store 2 different datatypes took on existing database don't have choice.
in case better cast int
varchar
other way round:
left join othertable ot on column = cast(t.id varchar(10))
Comments
Post a Comment