我向SQL存储过程发送了2个参数。它可以工作,但是当我尝试将局部变量与它连接时它不会。
这有效:
exec DeansSMSDB.dbo.ADD_SMS_InQueue @CellNo, 'Dear customer, Your complaint has been registered and your complaint no. is'
但这不是:
exec DeansSMSDB.dbo.ADD_SMS_InQueue @CellNo, 'Dear customer, Your complaint has been registered and your complaint no. is' + @ComplaintID
我需要连接@ComplaintID,但是如何?
答案 0 :(得分:2)
创建另一个变量:
declare @arg varchar(8000) = 'Dear customer, Your complaint has been registered and your complaint no. is' + cast(@ComplaintID as varchar(255);
exec DeansSMSDB.dbo.ADD_SMS_InQueue @CellNo, @arg;
请注意,如果@ComplaintId
是数字,则需要将其强制转换为字符串,以便将+
运算符用作字符串连接运算符。
答案 1 :(得分:0)
您可以尝试两步方法,将执行结果转储到一个小的@T临时表中。然后从@T连接中快速选择连接:
create table tableX(input_field_name varchar(20)NULL, output_field_name varchar(20)NULL)
插入tableX值('address','addr')
创建程序testP as 从tableX中选择input_field_name,其中output_field_name ='addr'
声明@T表(F1 varchar(20)) 声明@v varchar(10)='my'
插入@T exec testP
从@T