sql cláusula where con mayúsculas y minúsculas

Blockquote

DECLARE @Symbol nvarchar(50);
DECLARE @EnDate1 Datetime;
DECLARE @StDate1 Datetime;
SET @Symbol = 'RIM12f'
SET @EnDate1 = '05/08/2012 9:00'
SET @StDate1 = '05 / 07 / 2012 12 : 00'
SELECT  *
FROM   Siri
WHERE (DATEADD(D, 0, DATEDIFF(D, 0, Date)) BETWEEN @StDate1 AND @EnDate1)
  AND  CASE Symbol = WHEN @Symbol = 'ALL'
                     THEN Symbol
                     ELSE Symbol LIKE LEFT(@Symbol, len(@Symbol) - 3) + '%'
       END

it does not works as same but it works with else @Symbol but i need all symbols like LEFT(@Symbol, len(@Symbol) - 3) + '%' if @Symbol other than all

preguntado el 30 de junio de 12 a las 14:06

Don't think it's sql server, looks like one of those unholy confabulations like FORBOL to me. :) -

3 Respuestas

Modify you Case expression:

 Symbol LIKE CASE @Symbol WHEN 'ALL'
                     THEN Symbol
                     ELSE LEFT(@Symbol, len(@Symbol) - 3) + '%'

Respondido el 30 de junio de 12 a las 15:06

DECLARE @Symbol nvarchar(50); 
DECLARE @LikeSymbol nvarchar(50); 

DECLARE @EnDate1 Datetime; 
DECLARE @StDate1 Datetime; 
SET @Symbol = 'RIM12f' 
SET @EnDate1 = '05/08/2012 9:00' 
SET @StDate1 = '05 / 07 / 2012 12 : 00' 
SET @LikeSymbol = LEFT(@Symbol, length(@Symbol) - 3) + '%'
SELECT  * 
FROM   Siri 
WHERE (DATEADD(D, 0, DATEDIFF(D, 0, Date)) BETWEEN @StDate1 AND @EnDate1) 
AND (
(@Symbol = 'All')
OR
(Symbol Like @LikeSymbol)
)

A guess seeing as the intent of your query is far from clear

Respondido el 30 de junio de 12 a las 15:06

You cannot have in CASE ambas = y anidado LIKE.. you can use LIKE or using OR y AND constructions.. (like suggested @Tony Hopkinson)

Here is modified case:

Symbol like CASE WHEN @Symbol = 'ALL'
                     THEN Symbol
                     ELSE LEFT(@Symbol, len(@Symbol) - 3) + '%'
END

Respondido el 30 de junio de 12 a las 15:06

Sorry, Error on copy paste, try again.. i just run it on SQL SERVER 2000 and it's working OK - ALZ

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.