日期:2014-05-18  浏览次数:20469 次

存储过程,在运行时总是说go附近有语法错误!
下面是我的存储过程,在运行时总是说go附近有语法错误!

请高手指点一下:

-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE E_V_Fee 
 -- Add the parameters for the stored procedure here
 @startdate datetime,
 @enddate datetime
AS
BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;

  -- Insert statements for procedure here
 
if exists(select * from sysobjects where id=object_id(N'[dbo].[tb]') and OBJECTPROPERTY(id,N'IsUserTable')=1) 
DROP TABLE [dbo].[tb]
GO 
 

CREATE TABLE [dbo].[tb](西药费 INT,中成药费 INT,中草药费 INT,材料费 INT,输血费 INT,输氧费 INT,注射费 INT,
手术费 INT,其他治疗费 INT,CT INT,MRI INT,X光 INT,检验费 INT,医技检查 INT,其他检查费 INT,
特需服务费 INT,诊查费 INT,留观床位费 INT,其他 INT,TOTAL INT)
GO

INSERT [tb]
SELECT sum(XYFee),sum(ZCYFee),sum(ZYFee),sum(MaterialFee),sum(BloodFee),sum(OxygenFee),sum(ShotFee)
,sum(OperationFee),sum(TreatmentFee),sum(CTFee),sum(MRIFee),
sum(XFee),sum(AssayFee),sum(YJJCFee)+sum(QTYJJCFee)+sum(BFee)+sum(HeartBrainFee),sum(CheckFee),sum(SpecialServiceFee)
,sum(InspectFee) ,sum(ClinicBedFee),sum(OtherFee),sum(XYFee)+sum(ZCYFee)+sum(ZYFee)+sum(MaterialFee)+sum(BloodFee)+sum(OxygenFee)+sum(ShotFee)
+sum(OperationFee)+sum(TreatmentFee)+sum(CTFee)+sum(MRIFee)+sum(XFee)+sum(AssayFee)+sum(YJJCFee)
+sum(QTYJJCFee)+sum(BFee)+sum(HeartBrainFee)+sum(CheckFee)+sum(SpecialServiceFee)+sum(InspectFee)
+sum(ClinicBedFee)+sum(OtherFee)
from tbpaymentdetail where cancelpaidnum is null and receivedby <>'' 
and paymentdate between @startdate and @enddate

SELECT 项目,sum(金额) as 费用
FROM [tb]
  UNPIVOT(金额 FOR 项目 IN(西药费,中成药费,中草药费,材料费,输血费,输氧费,注射费,手术费
  ,其他治疗费,CT,MRI,X光,检验费,医技检查,其他检查费,特需服务费,诊查费
  ,留观床位费,其他,TOTAL))b group by 项目
END
GO



------解决方案--------------------
过程内不能用GO,用GO意味着你的过程代码到GO那里结束.
------解决方案--------------------
go 在存储过程里说明存储过程结束 
sqlvser一看到这个字 就认为后面的事情后这个存储过程无关了