Source Code : case statement in select query in sql

case statement in select query in sql

i need to set the column value of the destination table based on the two values of the select statement, some thing like the below example.

insert into table table_name
( value1, value 2,value 3)

select (value 1,value2 ,
case value3

when value1 = 'somevalue' &&* value2 = 'somevalue'

then 'x'

else 'y'
End

from table_name.can any one help me to find out how to update the a column in based on the two previous column values in the same select query?

i have tried with the below sample example to understand but it was failed to parse.

INSERT INTO HumanResources.departmentcopy  
( DepartmentID,GroupName,Name,temp)

SELECT DepartmentID,GroupName,Name,
CASE temp
WHEN  DepartmentID = 1 && Name = 'Engineering and Research'
THEN 'sucessful'
ELSE 'unsucessful'
END
FROM HumanResources.department

INSERT INTO HumanResources.departmentcopy(DepartmentID, GroupName, Name, temp)
SELECT  DepartmentID,
  GroupName,
  Name,
  CASE WHEN DepartmentID = 1 AND Name = 'Engineering and Research'
  THEN 'sucessful' ELSE 'unsucessful' END
FROM HumanResources.department

&& is not valid in SQL. Use AND to append a condition.

<code>INSERTINTO HumanResources.departmentcopy( DepartmentID,GroupName,Name,temp)SELECT  DepartmentID,
  GroupName,
  Name,CASEWHEN DepartmentID =1AND Name ='Engineering and Research'THEN'sucessful'ELSE'unsucessful'ENDFROM HumanResources.department</code>