I have two tables,
Database 1:
Table 1:
Id -001(int)
Name -xxx(varchar)
Male -0 (bit)
Female-1 (bit)
Database 2:
Table 2:
Id -1 (int)
Ca.Name-yyy (varchar)
Gender - M or F (varchar)
These are my tables. I want to update data from database2, Table 2 to database1, table1. So i create update query. But I have problem with Gender field
Select 'UPDATE T1
SET T1.MALE ='+ CASE WHEN r.Gender = 'M' THEN 0 ELSE 1 END
FROM T2 As r
In the below code, what I starred I have a doubt how to use if statement here. Any one understand rectify my problem?
Replace column values based on checking logical conditions in R DataFrame is pretty straightforward. All you need to do is select the column vector you wanted to update and use the condition within [] . The following example demonstrates how to update DataFrame column values by checking conditions on a numeric column.
To replace a column value in R use square bracket notation df[] , By using this you can update values on a single column or on all columns. To refer to a single column use df$column_name .
Use case when
for this purpose.
Follow this question :
SQL Server: CASE WHEN OR THEN ELSE END => the OR is not supported
CASE
WHEN GENDER='M' THEN 0
ELSE 1
END
This can be in your case.
For more syntax details: CASE (Transact-SQL)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With