sql - insert select with if else condition -
i have 2 tables, table1 , table2, , using
insert table1 ( col1, col2, col3 ) select ( cola, colb, colc ) table2 but logic between col3 , colc this:
if colc = 'a' col3 = y else col3 = n what's sql this, using sql server 2005.
you can use case expression:
insert table1 ( col1, col2, col3 ) select cola, colb, case when colc = 'a' 'y' else 'n' end -- alternatively: -- case colc when 'a' 'y' else 'n' end table2
Comments
Post a Comment