块引用
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
它不一样,但它可以与 else @Symbol 一起使用,但我需要所有符号,如 LEFT(@Symbol, len(@Symbol) - 3) + '%' if @Symbol 不是所有