-1
存儲過程引發錯誤:「關鍵字附近的語法錯誤,其中'。」
error SQL (error 156) [SQLSTATE 4200] "Incorrect syntax near the keyword 'where'."
該存儲過程並不順利通過INSERT
語句填充表,但我一直在運行時出現此錯誤。我不知道如何解決這個錯誤。
這裏是PROC:
ALTER PROCEDURE [dbo].[BuildTable]
AS
declare @QueryTxt as varchar(max)
declare @QueryName as varchar(50)
declare @ColumnVal as int
declare @CountVal as varchar(50)
declare @isFirst char(1)
declare @currentDT as varchar(20)
declare @savdate as datetime
BEGIN
set @isFirst = 'Y';
set @currentDT = convert(varchar(20),current_timestamp,110);
declare c1 cursor for select queryname, querytext from subsqueries
open c1
fetch next from c1 into @queryname, @querytxt
while @@FETCH_STATUS = 0
begin
--call stored proc
exec InformixQuery @querytxt, @ColumnVal output
set @CountVal = ltrim(str(@ColumnVal))
if @isFirst = 'Y'
begin
exec ('insert into TblHistory (' + @queryname + ',transdate) values(' + @CountVal + ',' + '''' + @currentDT + '''' + ')')
set @isFirst = 'N'
end
else
begin
exec ('update TblHistory set ' + @queryname + ' = ' + @CountVal + ' where transdate = ' + '''' + @currentDT + '''')
end
fetch next from c1 into @queryname, @querytxt
end
close c1
deallocate c1
end
爲什麼你有mysql標記?這似乎是sql server – Kritner
嘗試打印您的exec更新語句,而不是通過它來確認它是您認爲的並且有效的語法。 – Kritner