Urgent - Is this use of CASE statement in Teradata correct

Database

Urgent - Is this use of CASE statement in Teradata correct

Hi,

REPLY URGENTLY NEEDED.
Is this use of CASE statement in Teradata correct

For example:

Select COLUMN1,
(Case When Parameter1 = 'x'
Then
(Select COLUMN2
From TABLEX... )
Else
(Select COLUMN2
From TABLEY... )
From TABLE A...

Thanks In Advance.
4 REPLIES

Re: Urgent - Is this use of CASE statement in Teradata correct

Do teradata allow using of select statement in the case statement?

Re: Urgent - Is this use of CASE statement in Teradata correct

No, but you can create derived tables and use columns from those in the CASE statement:

Select COLUMN1,
Case When Parameter1 = 'x'
Then
TABLEX.COLUMN2
Else
TABLEY.COLUMN2
End
From TABLE A...
,(Select COLUMN2
From TABLEX... )
,(Select COLUMN2
From TABLEY... )

Usually, you can accomplish the same thing with this syntax. You'll need to add the join criteria between TABLE A and the derived tables.

Re: Urgent - Is this use of CASE statement in Teradata correct

The kind of case statement that you are trying to use works only in stored procedures (and that too not in a select query, but the normal "switch - case" like in C/C++/JAVA ).

You probably need some (possibly left outer) joins and derived tables like others suggested.

Of course the actual solution is more or less dependent on what you are trying to achieve.

Re: Urgent - Is this use of CASE statement in Teradata correct

Hi,
No we can't use the select statement...

Regds,
sachin