I wanted to do a condition wherein I put values (000000) in DATE_COMPLETED if it see’s the FLAG_CLOSED = Y and if its not Y then do nothing
SELECT
"JOB",
"SUFFIX",
"SUFFIX",
"DATE_COMPLETED",
"FLAG_CLOSED",
CASE "DATE_COMPLETED"
WHEN "FLAG_CLOSED"='Y'
THEN "DATE_COMPLETED"='000000'
END "DATE_COMPLETED"
FROM "JOB_OPERATIONS"
What I got
SQL Execution Error
[LNA][PSQL][SQL Engine]Syntax Error: SELECT
"JOB",
"SUFFIX",
"SUFFIX",
"DATE_COMPLETED",
"FLAG_CLOSED",
CASE "DATE_COMPLETED" WHEN "FLAG_CLOSED" << ??? >> = 'Y' THEN "DATE_COMPLETED" = '000000' END "DATE_COMPLETED"
FROM JOB_OPERATIONS
2
Answers
It looks like you’re attempting to change the
DATE_COMPLETED
column in your table. You can’t do that with a SELECT statement. CASE / WHEN / THEN helps construct output. UPDATE statements allow clauses likeDATE_COMPLETED='000000'
that change columns.Try something like this.
I named your CASE-computed output column
CLOSED_DATE_COMPLETED
so it won’t collide with theDATE_COMPLETED
colum you already mentioned.Syntax is either:
… or:
To return the value of
DATE_COMPLETED
depending on the flag, you can do this:Beware that you need to produce a coherent column type. If
DATE_COMPLETED
is not text, you’ll need to cast it.