我按照提供的答案。
SELECT 'EXEC sp_whatever ' + CAST(field1 AS varchar) + ', ' + CAST(field2 AS varchar)
FROM your_table
以下是我想要实现的目标。有谁能告诉我我在哪里弄错了。我想传递int,bit,int,datetime类型的4个参数。
在转换varchar值时,显示错误为" 转换失败' EXEC My_SP'数据类型int。"
SELECT 'EXEC My_SP ' +cast(90 as int)+','+cast(0 as bit)+','+cast(1 as int)+','+ CAST('2016-04-20 00:00:00.000' as datetime)
SELECT CONCAT('EXEC USP_GetSchedular ', cast(90 as varchar(max)), ',', cast(0as varchar(max)), ',', cast(1 as varchar(max)), ',', '''2016-04-20''')
from tbl1l Join
tbl2 p
On l.PromoCode=p.PromoCode and StatusId in(Select StatusId
From Status
Where [Status] NOT IN('Deleted','Closed','Rejected By ISAdmin','RejectedBySales','Expired'))
and l.IsDealRegLead=1 and l.IsAntipiracy=0 and l.ISLHLead=0 and convert(date,l.createddatetime)<='2016-04-20'
答案 0 :(得分:0)
使用<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script type="text/javascript" src="./script.js"></script>
<h2>
<a href="http://fiddle.jshell.net/0hcod561/1/show/light/#" id="addScnt">
Add Another Input Box
</a>
</h2>
<table style="display:none" id="template">
<tr>
<td>
<label for="p_scnt_$">
<input type="text" class="iptArea" id="p_scnt_$"
size="20" name="p_scnt_$" value="" placeholder="Input Value">
</label>
<a href="#" class="remScnt">Remove</a>
</td>
</tr>
</table>
<table id="p_scents">
<tr>
<td>
<label for="p_scnt">
<input type="text" class="iptArea" id="p_scnt"
size="20" name="p_scnt" value="" placeholder="Input Value">
</label>
</td>
</tr>
</table>
运算符:
CONCAT
或SELECT CONCAT('EXEC My_SP ', 90, ',', 0, ',', 1, ',', '''2016-04-20''')
将所有连接的部分添加到varchar。
您可以在此处阅读CAST
:https://msdn.microsoft.com/en-us/library/ms190309(v=sql.120).aspx
P.S。如果只想执行你的SP:
Data Type Precedence (Transact-SQL)
答案 1 :(得分:0)
如果要将这些值连接在一起,则需要将它们作为varchars加入
SELECT
'EXEC My_SP '
+cast(90 as VARCHAR(2))
+','
+cast(0 as CHAR(1))
+','
+cast(1 as CHAR(1))
+','
+ CAST('2016-04-20 00:00:00.000' as VARCHAR(25));
这不会执行它,只需选择它为1个字符串。
如果要使用这些参数执行存储过程,则语法为
EXECUTE procedure_name parameter01,parameter02,... parameterN:
EXEC My_Sp 90, 0, 1, '20160420'
参数应与存储过程中定义的顺序相同。
因此,如果“90 as INT”是第一个参数,则应首先调用它,如果datetime实际上是最后一个参数,则应该最后调用它。
唯一的解决方法是知道参数名称并以这种方式引用它们。
示例:
CREATE PROCEDURE test_sproc @x int, @y datetime
AS
BEGIN
SELECT
@x as [x]
, @y as [y]
END
EXECUTE test_sproc @x = 90, @y = '20160420';