|
|
Archives of the TeradataForum
Message Posted: Sun, 23 Apr 2006 @ 19:53:51 GMT
Subj: | | Re: Help needed for writing SQL |
|
From: | | Dieter Noeth |
Naveen Kambhoji wrote:
| Now I Came to know from users that they can also denote NULL as 'E' (Empty). In plain english my requirements are | |
| If Name = 'A' and (Value IS NOT NULL OR VALUE <> 'E' ) Then VALUE else get the value of the name 'B'. Basically I need to select name
value pairs for each member in a web based application. | |
Just put it into the CASE:
SELECT
MemID,
COALESCE(MAX(CASE WHEN Name = 'A' AND VALUE <> 'E' THEN Name END),
MAX(CASE WHEN Name = 'B' THEN Name END)
) AS Name,
COALESCE(MAX(CASE WHEN Name = 'A' AND VALUE <> 'E' THEN Value END),
MAX(CASE WHEN Name = 'B' THEN Value END)
) AS Value
FROM TheTable t1
GROUP BY 1;
Similar for Frank's query...
Dieter
| |