我使用SQL Server 2008 R2的 我有存儲過程是這樣的:SQL選擇case語句
CREATE PROCEDURE Get_Code_Tourne_Matin
-- Add the parameters for the stored procedure here
@The_FA int,
@The_Jour int,
@The_Insee varchar(10)
AS
BEGIN
declare @TheCode varchar(250)
set @TheCode = case
when exists (SELECT T_TOURNE_LABEL.LIBELLE
FROM TOURNE
LEFT JOIN T_TOURNE_LABEL ON TOURNE.LIB_TOURNE = T_TOURNE_LABEL.NOID
WHERE THE_FA = @The_FA AND
NO_INSEE = @The_Insee AND
JOUR = @The_Jour AND
(datepart(hh, LE_HEURE) between 13 and 23 or datepart(hh, LE_HEURE) between 0 and 6)) then LIBELLE
when exists (SELECT LIBELLE
FROM TOURNE
LEFT JOIN T_TOURNE_LABEL ON TOURNE.LIB_TOURNE = T_TOURNE_LABEL.NOID
WHERE THE_FA = @The_FA AND
NO_INSEE = @The_Insee AND
JOUR = 0 AND
(datepart(hh, LE_HEURE) between 13 and 23 or datepart(hh, LE_HEURE) between 0 and 6)) then LIBELLE
else '00'
end
RETURN @TheCode
END
我只是想返回libelle。
先用3變量選擇的時候才發現那麼如果有2個可變運行選擇的時候才發現,然後retrun的libelle retrun的libelle
其他
其他retrun「00」
似乎對LIBELLE
語法錯誤有什麼想法?
Libelle的()括號內只存在,但你要訪問他們的外面。 – 2013-03-05 09:11:36
(用'JOUR = @ The_Jour'),莫不是也是一行'JOUR = 0'? – 2013-03-05 09:12:08