Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
INSERT INTO with condition
Message
From
21/08/2014 17:08:56
 
 
To
21/08/2014 17:06:07
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01606222
Message ID:
01606224
Views:
56
>>I am doing an INSERT INTO from a SELECT. In the SELECT list of fields, I need to apply a condition to either use one field or another. What would be the syntax to support that?
>
>Maybe CASE in the select?

Right, yes, you can use a CASE
insert into MyTable  (Column1, Column2, Column3 )
   select    case when SomeColumn = 'Use Column1a' then Column1a else Column1b end as Column1,   Column2, Column3 From SomeOtherTable
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform