我创建了这些,但是它带有多个参数,但是当它执行存储过程时,我得到一个错误:
将NVARCHAR值'141,139'转换为数据类型int时转换失败。
这是我的代码:
BEGIN
SET NOCOUNT ON;
DECLARE @temp NVARCHAR(MAX)
SET @temp = REPLACE(@Voucher_ID, '''', '')
SELECT
av.Voucher_No, avl.Ref_Dr_Cr, Av.Voucher_Amount,
avl.Ledger_Amount, AVLI.Quantity, AVli.Rate, AVli.PCS,
AVLI.Inventory_Total, AVli.Discount,al.Ledger_Name,
st.Stock_Name, st.HSN_Code, al.address,
(SELECT CASE WHEN al.Ledger_Name <> 'Rounded Off' AND avl.Ref_Dr_Cr = 'Dr' THEN al.GSTIN_No ELSE '' END) AS GSTIN_No,
(SELECT CASE WHEN avl.Ref_Dr_Cr = 'Dr' AND al.Ledger_Name <> 'Rounded Off' THEN al.Ledger_Name ELSE '' END) AS Party_Name,
(SELECT CASE WHEN al.Ledger_Name <> 'Rounded Off' AND avl.Ref_Dr_Cr = 'Dr' THEN al.Address ELSE ''END) AS Ledger_Address,
(SELECT CASE WHEN al.Ledger_Name = 'Rounded Off' AND avl.Ref_Dr_Cr = 'Dr' THEN CAST(avl.Ledger_Amount AS NVARCHAR(100)) ELSE '' END) AS Amount,
(SELECT CASE WHEN al.Ledger_Name LIKE '%IGST%'THEN CAST(avl.Ledger_Amount AS NVARCHAR(100)) ELSE '' END) AS IGST,
(SELECT CASE WHEN al.Ledger_Name LIKE '%SGST%'THEN CAST(avl.Ledger_Amount AS NVARCHAR(100)) ELSE '' END) AS SGST,
(SELECT CASE WHEN al.Ledger_Name LIKE '%CGST%'THEN CAST(avl.Ledger_Amount AS NVARCHAR(100)) ELSE '' END) AS CGST,
AVLI.UOM
FROM
Acc_Voucher AV
INNER JOIN
Acc_Voucher_Ledger AVL ON Av.Voucher_Id = avl.Voucher_ID
LEFT JOIN
Acc_Voucher_Ledger_Inventory AVLI ON AVL.Voucher_Ledger_Id = avli.Voucher_Ledger_Id
INNER JOIN
Acc_Ledger AL ON AVL.Ledger_Id = al.Ledger_ID
LEFT JOIN
Acc_Stock_Item St ON avli.Stock_Item_Id = st.Stock_Item_Id
WHERE
av.Voucher_ID IN (@Voucher_ID)
END
有什么想法吗?谢谢。
答案 0 :(得分:0)
使用IN条件时,应使用Dynamic SQL通过变量传递多个值。 尝试如下操作:
declare @voucherid nvarchar(1000)='1,2'
declare @sql nvarchar(max)='
select * from Customer
where id in ('+@voucherid+')'
print @sql
EXECUTE sp_executesql @sql