CREATE PROCEDURE GetDisplayNameByBatchAttibuteValues
(
@ListItemValue varchar(8000),
@ListDisplayName varchar(8000) output
)
AS
begin
declare @str varchar(8000)
set @str = ' '
select @str = @str + ', ' + ListDisplayName from ProductAttributeLookupListItems where ListItemValue in(@ListItemValue)
set @ListDisplayName=stuff(@str,1,1, ' ')
print @ListDisplayName
end
GO
@ListItemValue 传递14,18,22这样的子符串
错误:
System.Data.SqlClient.SqlException: 将 varchar 值 '14,18,22 ' 转换为数据类型为 int 的列时发生语法错误。
请高手指教!感激涕零~
------解决方案--------------------------------------------------------
CREATE PROCEDURE GetDisplayNameByBatchAttibuteValues
(
@ListItemValue varchar(8000),
@ListDisplayName varchar(8000) output
)
AS
begin
declare @str varchar(8000)
declare @tb table(a int)
while charindex( ', ',@s)> 0
begin
insert @tb values(cast(left(@s,charindex( ', ',@ListItemValue )-1) as int))
set @s = stuff(@ListItemValue ,1,charindex( ', ',@ListItemValue ), ' ')
end
insert @tb values(@ListItemValue)
set @str = ' '
select @str = @str + ', ' + ListDisplayName from ProductAttributeLookupListItems where ListItemValue in(select a from @tb)
set @ListDisplayName=stuff(@str,1,1, ' ')
print @ListDisplayName
end
GO