Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set column value

Status
Not open for further replies.

techipa

Programmer
Feb 12, 2007
85
US
Hi All,

I create the temp table in my query. The temp table has a varchar column col1 which stores the data like

-N- NONE
-N- NONE
-N- NONE
*P* NONE
-N- NONE
-N- NONE
*F* NONE

I need to update the col2 (datatype bit) in the same table based on the data in col1.
If Col1 has *F* NONE or *P* NONE then col2 is 1
If col1 has -N- NONE then Col2 is 0

Can anyone tell me how to implement this change?

Thanks,
-techiPA
 
I could write two update statements to implement this change but I wanted to know if we can write in just one update.

UPDATE #tbl1
SET Remarkbit = 1
WHERE (Remark LIKE '%*P*%')OR (Remark LIKE '%*F*%')

UPDATE #tbl1
SET Remarkbit = 0
WHERE (Remark LIKE '%-N-%')

 
This should work (tested):

Code:
UPDATE #tbl1
    SET Remarkbit = case when Remark Like '*%' then 1 else 0 end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top