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

Conditional update

Status
Not open for further replies.

korzen

Programmer
May 30, 2003
6
US
I'm trying to write a single query to update a value in one field based on a value in another field. The updated value is pulled from one of two tables, which is determined by the value in the second field.

I've tried this:

UPDATE
T1 tbl
SET
tbl.F1 =
(
IF
(
tbl.F2 = 1,
(SELECT T2.F2 FROM T2 WHERE T2.F1 = tbl.F1),
IF
(tbl.F2 = 2,
(SELECT T3.F2 FROM T3 WHERE T3.F1 = tbl.F1),
tbl.F1
)
)
)

Pervasive apparetnly doesn't like this usage io IF and SELECT. Does anyone have any ideas?

 
I wonder if it's syntax? This is waht I got out of my manual (PSQL 7)

IF

IF Boolean_value_expression
THEN SQL_statement_list
[ if_statement_elseif_clause ... ]
[ ELSE SQL_statement_list ]
END IF

where

if_statement_elseif_clause ::=
ELSEIF Boolean_value_expression
THEN SQL_statement_list
SQL_statement_list ::= { SQL_statement ; } ...
Boolean_value_expression ::= see Boolean Value Expressions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top