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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPDATE syntax problem

Status
Not open for further replies.

rjbutler

Programmer
Joined
Nov 25, 2003
Messages
3
Location
GB
Sorry but I'm a bit of a SQL novice and having trouble setting a bit value based on other numeric column values.
What I want to do is somthing like this (in pseudo speak!)

UPDATE MyTable
SET MyBitColumn = ((MyNumeric1 > 0 ) OR (MyNumeric2 >0))
WHERE etc.

What is the correct sysntax to evaluate the logic expression?

Many thanks!
 
Sorry!
More specifically I need:

UPDATE MyTable
SET MyBitColumn = ((MyNumericColumn1 + MyNumericColumn2) <> 0 )
WHERE etc.

Thanks.
 
Give this a go.

UPDATE MyTable
SET MyBitColumn = MyNumericColumn1 + MyNumericColumn2
WHERE MyNumericColumn1 + MyNumericColumn2 <> 0
and etc....

Brett
 
I don't see why you need to store redundant data. Calculate it when you need it.

Code:
select case when MyNumericColumn1 + MyNumericColumn2) <> 0 
  then 1 else 0 end as q
from t
 
Thanks guys - got it working now.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top