General discussion

Locked

Sql query problem

By allooyaa ·
This query is incorrect one :
SELECT DBNAME
FROM SYSIBM.SYSTABLEPART
WHERE DBNAME like
CASE DAYOFWEEK(CURRENT DATE)
WHEN 1 THEN 'B11%'
ELSE 'B12%'
END'
****it gives a msg:An incorrect value is used in a LIKE comparison (line 3, position 10). If i used the '=' equal sign instead of like then it works ok.. This sql is run under DB2. I think that "like" does not work with CASE .

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Sql query problem

by MedievalDude In reply to Sql query problem

I've never seen a case statement used quite like that before. Here's how I would do it.

SELECT DBNAME
FROM SYSIBM.SYSTABLEPART
WHERE (DAYOFWEEK(CURRENTDATE) = 1 AND DBNAME LIKE 'B11%') OR
(DAYOFWEEK(CURRENTDATE) <> 1 AND DBNAME LIKE 'B12%')

Collapse -

Sql query problem

by allooyaa In reply to Sql query problem
Collapse -

Sql query problem

by allooyaa In reply to Sql query problem

This question was closed by the author

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums