Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2005 运行sp_executesql查询需要参数@语句_Sql Server 2005_Stored Procedures - Fatal编程技术网

Sql server 2005 运行sp_executesql查询需要参数@语句

Sql server 2005 运行sp_executesql查询需要参数@语句,sql-server-2005,stored-procedures,Sql Server 2005,Stored Procedures,我不确定如何解决此错误: 过程或函数“sp_executesql”需要未提供的参数“@statement” 对于此查询: DECLARE @a INT DECLARE @b VARCHAR SET @a = 1 WHILE @a < 30 BEGIN set @b = @a exec sp_executesql update source_temp set pmt_90_day = pmt_90_day + convert(money,'trans_total_'+@b)+N'

我不确定如何解决此错误:

过程或函数“sp_executesql”需要未提供的参数“@statement”

对于此查询:

DECLARE @a INT 
DECLARE @b VARCHAR 
SET @a = 1

WHILE @a < 30
BEGIN
set @b = @a  
exec sp_executesql update source_temp set pmt_90_day = pmt_90_day + convert(money,'trans_total_'+@b)+N'
    N'where convert(datetime,'effective_date_'+@b)+N' <= dateadd(day,90,ORSA_CHARGE_OFF_DATE)
    and DRC_FLAG_'+@b = 'C'''

SET @a = @a + 1
END
DECLARE@a INT
声明@b VARCHAR
设置@a=1
而@a<30
开始
设置@b=@a
exec sp_executesql更新源临时设置付款90_日=付款90_日+转换(货币,'trans_total_'+@b)+N'
其中convert(datetime,'effective_date++@b)+N'存储的“sp_executesql”过程需要执行单个字符串参数@语句

你的绳子完全不正常了。。。。。您需要在任何“固定”字符串部分前面加上一个N“…”以使其成为Unicode字符串,但这里的情况肯定不是这样

我想你可能想试试这个:

DECLARE @a INT 
DECLARE @b VARCHAR(2)

SET @a = 1

DECLARE @statement NVARCHAR(500)

WHILE @a < 30
BEGIN
    SET @b = CAST(@a AS VARCHAR(2))

    SET @statement = 
        N'update source_temp set pmt_90_day = pmt_90_day + ' + 
             'convert(money, ''trans_total_' + @b + ''') ' + 
             'where convert(datetime, ''effective_date_' + @b + ''')' +
             ' <= DATEADD(DAY, 90, ORSA_CHARGE_OFF_DATE) ' +
             'and DRC_FLAG_' + @b + ' = ''C'''

    exec sp_executesql @statement

    SET @a = @a + 1
END
DECLARE@a INT
声明@b VARCHAR(2)
设置@a=1
声明@statement NVARCHAR(500)
而@a<30
开始
设置@b=CAST(@a为VARCHAR(2))
SET@statement=
N'update source_temp set pmt_90_day=pmt_90_day+'+
“转换(货币),“转换总额”+@b+”)+
'其中转换(日期时间,'effective_date.'+@b++'')'+

“sp需要字符串类型的变量,而不是SQL语句。将SQL用单引号括起来:

 exec sp_executesql 'some SQL statement';
执行此操作时,请通过将每个单引号替换为两个单引号来转义语句中的任何单引号:

exec sp_executesql 'select 'AB' from dual';  -- wrong

exec sp_executesql 'select ''AB'' from dual';  -- right

我不知道什么是
N
。你认为是什么?它是某种角色集的演员吗?为什么您认为这是必要的?

N“”表示UNICODE(NVARCHAR)字符串我正在尝试在循环中动态运行更新,因此每次迭代都会以1的增量更新字段。它引用了ex:Iteration1使用有效日期,iteration2使用有效日期,等等。失败者:D得到这个错误必须声明标量变量@b,我不知道为什么,因为它声明的是最高级的-动态SQL几乎相当混乱,特别是如果你试图“合并”你的字段名和东西…痛苦地关闭。。将varchar值“生效日期”转换为数据类型int时,Msg 245,级别16,状态1,第1行转换失败