set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[FindLineLog]
-- Add the parameters for the stored procedure here
@lineNumber nvarchar(30),
@startdate datetime,
@stopdate 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
exec('SELECT LineNumber ,LineStatus, OrderNumber,BT,ReMark,Number,Leader,Technician
,(SELECT sum(Quantity) FROM DB_LineHarvest WHERE LogID=id)AS CurrentSUM --本次生产
,(SELECT Quantity FROM DB_Order WHERE ordernumber=DB_LineLOG.OrderNumber)AS Quantity --订单量
,(SELECT Describe FROM DB_Order WHERE ordernumber=DB_LineLOG.OrderNumber)AS Describe --型号
,convert(nvarchar(20), StartDate,120) AS StartTime --开始时间
,convert(nvarchar(20), StopDate,120) AS StopDate --结束时间
,(CASE WHEN DATEDIFF(hh,StartDate,getdate())<>0
THEN convert(nvarchar, DATEDIFF(hh,StartDate,getdate()))+'+'小时'+'
ELSE '+''+' END)
+ convert(nvarchar, DATEDIFF(mi,StartDate,getdate())%60 )+'+'分钟'+' AS Duration
FROM DB_LineLOG
WHERE LineNumber IN('+@lineNumber+')
AND DATEDIFF(day,StartDate,'+@startdate+')<=0
AND DATEDIFF(day,StopDate,'+@stopdate+')>=0')
END
运行后提示
消息 156,级别 15,状态 1,第 15 行
关键字 'END' 附近有语法错误。
(1 行受影响)
改了好久 一直没有改好 ,请高手帮下忙
------解决方案--------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[FindLineLog]
-- Add the parameters for the stored procedure here
@lineNumber nvarchar(30),
@startdate datetime,
@stopdate 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
exec('SELECT LineNumber ,LineStatus, OrderNumber,BT,ReMark,Number,Leader,Technician
,(SELECT sum(Quantity) FROM DB_LineHarvest WHERE LogID=id)AS CurrentSUM --本次生产
,(SELECT Quantity FROM DB_Order WHERE ordernumber=DB_LineLOG.OrderNumber)AS Quantity --订单量