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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -