Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to insert a value in a column based on a condition ?

$
0
0

Hi All,

The value of sProblemID will determine what value that will end up in [IncidentCategoryID],[IncidentDetailID] columns

when I try this code 

insert into Customers([IncidentCategoryID],[IncidentDetailID])
select
case when @sProblemID = 1 then 1 end as  [IncidentCategoryID] ,
case when @sProblemID = 1 then 11 end as [IncidentDetailID],
case when @sProblemID = 2 then 1 end as [IncidentCategoryID],
case when @sProblemID = 2 then 14 end as  [IncidentDetailID]

I am getting an error 

The select list for the INSERT statement contains more items than the insert list. The number of SELECT values must match the number of INSERT columns.

How to fix this error


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>