我收到错误
SQL错误(102):')'
附近的语法不正确
尝试将以下查询保存为存储过程时。
查询本身(删除"创建过程"以及开始/结束工作正常)并且没有语法错误,我已经搜索了所有,但是我有点卡住,它驱使我疯狂。
CREATE PROCEDURE "downdaly_file_info"()
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
begin
declare @file_name varchar(75)
declare @agent_number varchar(15)
declare @aid_batch varchar(15)
declare @aid_agent varchar(15)
declare @Policy_Company varchar(2)
declare @Policy_Province2 varchar(2)
declare @akey varchar(30)
select @aid_batch=aid from audit with(nolock) where atype='OUT-BATCH' and akey like '%'+@file_name+'%'
print @aid_batch
select @aid_agent=aid from audit with(nolock) where atype='OUT-AGENT' and aid like @aid_batch+'-%' and akey=@agent_number
print @aid_agent
select @akey=akey from audit with (nolock) where aid like @aid_agent+'-%' and atype='OUT-POLICY'
SET @Policy_Company=substring(@akey,15,2)
print @Policy_Company
SET @Policy_Province2 =
CASE
WHEN @Policy_Company = 'CG' THEN substring(@akey,19,2)
WHEN @Policy_Company = 'TR' THEN substring(@akey,20,2)
WHEN @Policy_Company = 'EL' THEN substring(@akey,20,2)
WHEN @Policy_Company = 'IC' THEN substring(@akey,22,2)
WHEN @Policy_Company = 'PI' THEN substring(@akey,20,2)
WHEN @Policy_Company = 'S&' THEN substring(@akey,20,2)
END
print @Policy_Province2
insert into #downdaly_file_data (Name_Of_File,
Agent_Number,
Policy_Number,
Transaction_Number,
Policy_Province,
Trans_Code,
Policy_Company,
Policy_Province2,
Eff_Date_Real
)
select @file_name,
@agent_number,
substring(akey,1,12),
SUBSTRING(adata,20,3),
substring(adata,171,2),
substring(adata,32,3),
@Policy_Company,
@Policy_Province2,
substring(adata,139,6)
from audit with (nolock)
where aid like @aid_batch+'%' and atype='OUT-POLICY'
end
答案 0 :(得分:1)
您无法在程序中添加这些信息
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
以下是可能的选项
CREATE { PROC | PROCEDURE } [schema_name.] procedure_name [ ; number ]
[ { @parameter [ type_schema_name. ] data_type }
[ VARYING ] [ = default ] [ OUT | OUTPUT | [READONLY]
] [ ,...n ]
[ WITH <procedure_option> [ ,...n ] ]
[ FOR REPLICATION ]
AS { [ BEGIN ]
此时,当您没有parameters
时,请不要添加括号。这是正确的方法
CREATE PROCEDURE Downdaly_file_info
AS
BEGIN
---SQL statment
END