我使用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