Toad World® Forums

Case statement issue (instead of cross connection query)

Is this even possible? Instead of a cross connection query from excel or I guess you can call it vlookup, I want to create a “case when then statement” that is searching a specific word in the table (Finding a word in the table that is not generated yet.)

When I execute the sql below it is giving me this error.

"[Sybase][ODBC Driver][Sybase IQ]Column ‘GNL00347_7R_1_DB’ not found"

SELECT DC_E_ERBS_EUTRANCELLFDD_RAW.DATE_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.HOUR_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.MIN_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.ERBS
, DC_E_ERBS_EUTRANCELLFDD_RAW.EUtranCellFDD
, SUM(DC_E_ERBS_EUTRANCELLFDD_RAW.pmRrcConnEstabAtt) AS Sum_pmRrcConnEstabAtt
, CASE WHEN DC_E_ERBS_EUTRANCELLFDD_RAW.EUtranCellFDD = GNL00347_7R_1_DB THEN TEST
END AS TEST_123
FROM dc.DC_E_ERBS_EUTRANCELLFDD_RAW DC_E_ERBS_EUTRANCELLFDD_RAW
WHERE ( “DC_E_ERBS_EUTRANCELLFDD_RAW”.“DATE_ID” = ‘2017-11-14’)
AND ( “DC_E_ERBS_EUTRANCELLFDD_RAW”.“ERBS” = ‘GNL00347’)
GROUP BY DC_E_ERBS_EUTRANCELLFDD_RAW.DATE_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.HOUR_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.MIN_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.ERBS
, DC_E_ERBS_EUTRANCELLFDD_RAW.EUtranCellFDD

Would using single quote marks help: = 'GNL00347_7R_1_DB’ ?

Thank you! This is the first syntax I have used and did not work but tried it again and it did worked [:)]

But I still have issue when searching multiple variables. See below

The error is…

[Sybase][ODBC Driver][Sybase IQ]Syntax error near ‘,’ on line 6

SELECT DC_E_ERBS_EUTRANCELLFDD_RAW.DATE_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.HOUR_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.MIN_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.ERBS
, DC_E_ERBS_EUTRANCELLFDD_RAW.EUtranCellFDD
, CASE WHEN DC_E_ERBS_EUTRANCELLFDD_RAW.EUtranCellFDD IN ( (‘GNL00347_7R_1_DB’, ‘GNL00347_9R_1_DB’) ) THEN 'BOWL FIELD LEVEL’
ELSE 'BOWL-LOWER-LEVEL-Concession and Suites’
END AS CALCULATED_COLUMN1
FROM dc.DC_E_ERBS_EUTRANCELLFDD_RAW DC_E_ERBS_EUTRANCELLFDD_RAW
WHERE ( “DC_E_ERBS_EUTRANCELLFDD_RAW”.“DATE_ID” = ‘2017-11-15’)
AND ( “DC_E_ERBS_EUTRANCELLFDD_RAW”.“ERBS” = ‘GNL00347’)
GROUP BY DC_E_ERBS_EUTRANCELLFDD_RAW.DATE_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.HOUR_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.MIN_ID
, DC_E_ERBS_EUTRANCELLFDD_RAW.ERBS
, DC_E_ERBS_EUTRANCELLFDD_RAW.EUtranCellFDD

I’ve found that for multiple variables in CASE-WHEN… statements it is better to split then up in stead of using an “IN” clause:

CASE

**WHEN DC_E_ERBS_EUTRANCELLFDD_RAW.EUtranCellFDD = ‘GNL00347_7R_1_DB’ THEN ‘BOWL FIELD LEVEL’ **

**WHEN DC_E_ERBS_EUTRANCELLFDD_RAW.EUtranCellFDD = ‘GNL00347_9R_1_DB’ THEN ‘BOWL FIELD LEVEL’ **
**ELSE ‘BOWL-LOWER-LEVEL-Concession and Suites’ **
END AS CALCULATED_COLUMN1

Your IN statement should work. Try taking off the outer set of parantheses.

IN (‘GNL00347_7R_1_DB’, ‘GNL00347_9R_1_DB’)