2 chenshiqiu chenshiqiu 于 2013.12.25 10:01 提问

存储过程:消息 156,级别 15,状态 关键字 'AND' 附近有语法错误。

USE [hazoon_insurance]
GO
/****** 对象: StoredProcedure [dbo].[p_bf_sgc] 脚本日期: 12/25/2013 08:58:06 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[p_bf_sgc]
@d1 INT,@d2 INT,@date1 VARCHAR(20),@date2 VARCHAR(20)
AS
IF @date1<>'' AND @date2<>''
IF @d1='0' AND @d2='0'
BEGIN
SELECT b.BI_NAME,sum(a.DCR_JG) AS bf1,count(a.DRC_ID) AS ts1,a.DCR_JG*100/sum(a.DCR_JG) AS zb1
FROM D_Car_Repair a,B_Insurance_Company b wherea.BI_ID =b.BI_ID group by a.BI_ID
AND a.DCR_ZF='0' AND a.DCR_STATE='2' AND CAST(a.DCR_ODATE AS DATETIME) BETWEEN @date1 AND @date2

    END
ELSE IF @d1='0'
    BEGIN

SELECT ly=@d2,b.BI_NAME,sum(a.DCR_JG) AS bf1,count(a.DRC_ID) AS ts1,a.DCR_JG*100/sum(a.DCR_JG) AS zb1
FROM D_Car_Repair a,B_Insurance_Company b where a.BI_ID =b.BI_ID group by a.BI_ID
AND a.DCR_ZF='0' AND a.DCR_STATE='2' AND CAST(a.DCR_ODATE AS DATETIME) BETWEEN @date1 AND @date2
END
ELSE IF @d2='0'
BEGIN
SELECT bxgs=@d1,b.BI_NAME,sum(a.DCR_JG) AS bf1,count(a.DRC_ID) AS ts1,a.DCR_JG*100/sum(a.DCR_JG) AS zb1
FROM D_Car_Repair a,B_Insurance_Company b where a.BI_ID =b.BI_ID group by a.BI_ID
AND a.DCR_ZF='0' AND a.DCR_STATE='2' AND CAST(a.DCR_ODATE AS DATETIME) BETWEEN @date1 AND @date2
END
ELSE
BEGIN
SELECT bxgs=@d1,ly=@d2,b.BI_NAME,sum(a.DCR_JG) AS bf1,count(a.DRC_ID) AS ts1,a.DCR_JG*100/sum(a.DCR_JG) AS zb1
FROM D_Car_Repair a,B_Insurance_Company b where a.BI_ID =b.BI_ID group by a.BI_ID
AND a.DCR_ZF='0' AND a.DCR_STATE='2' AND CAST(a.DCR_ODATE AS DATETIME) BETWEEN @date1 AND @date2
END

Csdn user default icon
上传中...
上传图片
插入图片