case-when

How to ORDER BY CASE in Doctrine2 (Symfony2)

こ雲淡風輕ζ 提交于 2019-11-29 00:10:16
问题 I want to run this query by using Doctrine in Symfony 2.3. But it seems like Doctrine does not understand CASE statement. Can anyone help? Thank you in advance! SELECT max(id) id, name FROM cards WHERE name like '%John%' GROUP BY name ORDER BY CASE WHEN name like 'John %' THEN 0 WHEN name like 'John%' THEN 1 WHEN name like '% John%' THEN 2 ELSE 3 END, name 回答1: If you are using createQueryBuilder then you can use like $query->addSelect("(CASE WHEN name like 'John %' THEN 0 WHEN name like

How do I use T-SQL's Case/When?

不羁的心 提交于 2019-11-28 19:07:01
I have a huge query which uses case/when often. Now I have this SQL here, which does not work. (select case when xyz.something = 1 then 'SOMETEXT' else (select case when xyz.somethingelse = 1) then 'SOMEOTHERTEXT' end) (select case when xyz.somethingelseagain = 2) then 'SOMEOTHERTEXTGOESHERE' end) end) [ColumnName], Whats causing trouble is xyz.somethingelseagain = 2 , it says it could not bind that expression. xyz is some alias for a table which is joined further down in the query. Whats wrong here? Removing one of the 2 case/whens corrects that, but I need both of them, probably even more

missing keyword error in oracle CASE WHEN sql statement

扶醉桌前 提交于 2019-11-28 14:34:07
I am writing a procedure in which i have sql statement which will insert values in TEMP_WF_WORKFLOW table using CASE WHEN statement. The condition is when STATUS_ID is 0 then the EVENT_ID=10003 and when STATUS_ID is 1 then EVETN_ID=10018 . When i try to use CASE WHEN for this its giving me error missing keyword.I dont know but is there any other way to do this if not using CASE WHEN statement. I am thinking about using cursor but dont know how to do this. Here is my query: CREATE OR REPLACE PROCEDURE ext_self_10003_sigwf AS BEGIN -- first empty TEMP_WF_WORKFLOW table EXECUTE IMMEDIATE

SQL Server CASE .. WHEN .. IN statement

十年热恋 提交于 2019-11-28 09:38:26
On SQL server 2005 I am trying to query this select statement SELECT AlarmEventTransactionTableTable.TxnID, CASE AlarmEventTransactions.DeviceID WHEN DeviceID IN( '7', '10', '62', '58', '60', '46', '48', '50', '137', '139', '142', '143', '164' ) THEN '01' WHEN DeviceID IN( '8', '9', '63', '59', '61', '47', '49', '51', '138', '140', '141', '144', '165' ) THEN '02' ELSE 'NA' END AS clocking, AlarmEventTransactionTable.DateTimeOfTxn FROM multiMAXTxn.dbo.AlarmEventTransactionTable It returns the error below Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'IN'. Please give me

How can I SELECT multiple columns within a CASE WHEN on SQL Server?

蓝咒 提交于 2019-11-28 06:22:11
I have searched this site extensively but cannot find a solution. Here is the example of my query: SELECT ActivityID, Hours = (CASE WHEN ActivityTypeID <> 2 THEN FieldName = (Some Aggregate Sub Query), FieldName2 = (Some other aggregate sub query) WHEN ActivityTypeID = 2 THEN FieldName = (Some Aggregate Sub Query with diff result), FieldName2 = (Some Other Aggregate Sub Query with diff result) END) obviously I'm leaving out a lot of the query, I just wanted to see if it's possible. I know I probably could just do the "CASE" twice but figured I would ask... Josh Anderson The problem is that the

missing keyword error in oracle CASE WHEN sql statement

你离开我真会死。 提交于 2019-11-27 08:30:09
问题 I am writing a procedure in which i have sql statement which will insert values in TEMP_WF_WORKFLOW table using CASE WHEN statement. The condition is when STATUS_ID is 0 then the EVENT_ID=10003 and when STATUS_ID is 1 then EVETN_ID=10018 . When i try to use CASE WHEN for this its giving me error missing keyword.I dont know but is there any other way to do this if not using CASE WHEN statement. I am thinking about using cursor but dont know how to do this. Here is my query: CREATE OR REPLACE

SQL Server CASE .. WHEN .. IN statement

浪子不回头ぞ 提交于 2019-11-27 03:03:53
问题 On SQL server 2005 I am trying to query this select statement SELECT AlarmEventTransactionTableTable.TxnID, CASE AlarmEventTransactions.DeviceID WHEN DeviceID IN( '7', '10', '62', '58', '60', '46', '48', '50', '137', '139', '142', '143', '164' ) THEN '01' WHEN DeviceID IN( '8', '9', '63', '59', '61', '47', '49', '51', '138', '140', '141', '144', '165' ) THEN '02' ELSE 'NA' END AS clocking, AlarmEventTransactionTable.DateTimeOfTxn FROM multiMAXTxn.dbo.AlarmEventTransactionTable It returns the

How can I SELECT multiple columns within a CASE WHEN on SQL Server?

对着背影说爱祢 提交于 2019-11-27 01:18:02
问题 I have searched this site extensively but cannot find a solution. Here is the example of my query: SELECT ActivityID, Hours = (CASE WHEN ActivityTypeID <> 2 THEN FieldName = (Some Aggregate Sub Query), FieldName2 = (Some other aggregate sub query) WHEN ActivityTypeID = 2 THEN FieldName = (Some Aggregate Sub Query with diff result), FieldName2 = (Some Other Aggregate Sub Query with diff result) END) obviously I'm leaving out a lot of the query, I just wanted to see if it's possible. I know I

SQL Server: CASE WHEN OR THEN ELSE END => the OR is not supported

眉间皱痕 提交于 2019-11-26 12:34:45
The OR in the WHEN clause of a CASE statement is not supported. How can I do this? CASE ebv.db_no WHEN 22978 OR 23218 OR 23219 THEN 'WECS 9500' ELSE 'WECS 9520' END as wecs_system That format requires you to use either: CASE ebv.db_no WHEN 22978 THEN 'WECS 9500' WHEN 23218 THEN 'WECS 9500' WHEN 23219 THEN 'WECS 9500' ELSE 'WECS 9520' END as wecs_system Otherwise, use: CASE WHEN ebv.db_no IN (22978, 23218, 23219) THEN 'WECS 9500' ELSE 'WECS 9520' END as wecs_system Darren CASE WHEN ebv.db_no = 22978 OR ebv.db_no = 23218 OR ebv.db_no = 23219 THEN 'WECS 9500' ELSE 'WECS 9520' END as wecs_system

OR is not supported with CASE Statement in SQL Server

折月煮酒 提交于 2019-11-26 05:53:59
问题 The OR operator in the WHEN clause of a CASE statement is not supported. How can I do this? CASE ebv.db_no WHEN 22978 OR 23218 OR 23219 THEN \'WECS 9500\' ELSE \'WECS 9520\' END as wecs_system 回答1: That format requires you to use either: CASE ebv.db_no WHEN 22978 THEN 'WECS 9500' WHEN 23218 THEN 'WECS 9500' WHEN 23219 THEN 'WECS 9500' ELSE 'WECS 9520' END as wecs_system Otherwise, use: CASE WHEN ebv.db_no IN (22978, 23218, 23219) THEN 'WECS 9500' ELSE 'WECS 9520' END as wecs_system 回答2: CASE