Monday, 15 September 2014

sql - How to select case when more column for inserting? -



sql - How to select case when more column for inserting? -

i need help insert select query complex me. logic below

insert thetable(a,customerno,item,b,c,d) select distinct case when ((select count(*) hesap customerno=e.customerno)0) select top 1, a,customerno,item+1,b,c,d dbo.table1 order ekno desc ) else select 100,e.customerno,e.item,0,e.defterid,'c' table2 e end

but can not that...

you can case on column basis only.

what can unioning 2 selects, , insert result. like

insert thetable(a,customerno,item,b,c,d) select ... (select count(*) hesap customerno=e.customerno) = 0 union select select 100,e.customerno,e.item,0,e.defterid,'c' (select count(*) hesap customerno=e.customerno) > 0

i'm sorry, cannot follow select, hope got idea. have separate 2 possibilities before union them, 1 row can exist each original row.

sql sql-server tsql

No comments:

Post a Comment