我還是新的存儲過程。在存儲過程中執行時語法不正確返回
任何人都可以幫助並告訴我這有什麼問題嗎?
Create PROCEDURE [dbo].[spCreateProductionReport]
@whereClause nvarchar(max)
As
Begin
declare @id int, @itemNum nvarchar(20), @datetimestamp datetime, @tStations_id int
declare @counter int, @itemNumPrev nvarchar(20)
set @counter = 0
set @itemNumPrev =''
set @whereClause = ''
SET NOCOUNT ON;
create table #Temp
(
id int,
itemNum nvarchar(20),
tStations_id int,
datetimestamp datetime,
groupID int
)
DECLARE db_cursor CURSOR FOR
select id,itemNo,tstations_id,datetimestamp
from
tProduction_Count @whereClause
--where datetimestamp between '2017-03-16 00:00:00' and '2017-03-16 23:59:59'
ORDER BY id ASC
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @id, @itemNum,@tStations_id, @datetimestamp
我得到的錯誤是: '消息102,級別15,狀態1,過程spCreateProductionReport,行42 附近有語法錯誤@WhereClause'。'
@whereClause變量是一個參數,還是你忘記'聲明'它? – Norsk
它應該是一個參數,我將使用whereClause從前端獲取字符串/文本並將其用作此處的篩選器 – MichaelJ