Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
declare @Qtr int =1;
 update Appraisal_QtrUsers_Details  set ( case when @Qtr=1 then Q1AppseKRA_SubDate
 when @Qtr=2 then Q2AppseKRA_SubDate
  when @Qtr=3 then Q3AppseKRA_SubDate
  when @Qtr=4 then Q4AppseKRA_SubDate else null end )= null
  where user_id=9177
Posted
Comments
Maciej Los 5-Aug-15 3:12am    
?Could you be so kind and provide more details about your issue...
At this moment we have no idea about your issue.

1 solution

Corrected sql is-


SQL
declare @Qtr int =1;
update Appraisal_QtrUsers_Details  
set  Q1AppseKRA_SubDate=(case when @Qtr=1 then null else Q1AppseKRA_SubDate end),
     Q2AppseKRA_SubDate=(case when @Qtr=2 then null else Q2AppseKRA_SubDate end),
     Q3AppseKRA_SubDate=(case when @Qtr=3 then null else Q3AppseKRA_SubDate end),
     Q4AppseKRA_SubDate=(case when @Qtr=4 then null else Q4AppseKRA_SubDate end)
where user_id=9177

The logic behind this query is if the column is not supposed to be updated with NULL value then just update it with the its current value and will not result in any value change.


Note: It would be better if you can share some business logic for this query so that it would be easier to suggest you more correct solution.


Thanks :)

 
Share this answer
 
Comments
sushil7350 6-Aug-15 0:40am    
it's not proper.. every column update every request...
i want one column update one time means
if qt=1 then only update Q1AppseKRA_SubDate
ad when qt=2 then only update Q2AppseKRA_SubDate
Not all updates
Suvendu Shekhar Giri 6-Aug-15 0:46am    
You are right. I already have mentioned that this query will update each and every column but aslo note that the value will not be changed for other columns because it updates to itself except the one column which will be set to NULL based on the condition. What is problem in that?

If you need me to explain more descriptively, please let me know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900