vendredi 22 juillet 2016

SQL case when with 2 different types of output

Table

c1     c2  c3
'a1'   1   'hi'
'b1'   2   'hee'
'c1'   3   null

When I do

select case when c3 is null then c2 else c1 end from Table

I get a "Conversion failed when converting" error.

I know that case when can only return 1 type, but is there a way to convert varchar to int/tinyint? If not, is there another way?

Aucun commentaire:

Enregistrer un commentaire