又来问问题了。
exec dbo.ExecSelectSql 'm_user','m_id,m_nick,m_img',' m_id in (Select Top 1 m_idoluid from m_my_otherinfo Where m_uid = 1) ',' m_id desc ',0
提示:将 varchar 值 '2,3,4,5,6' 转换为数据类型为 int 的列时发生语法错误。
Select Top 1 m_idoluid from m_my_otherinfo Where m_uid = 1
得到的值是:2,3,4,5,6
应该肿么解决啊?
------最佳解决方案-------------------- --该函数把传递过来的字符串转换成IN 后面的列表,可以处理以分号,逗号以及空格分隔的字符串
CREATE FUNCTION [GetInStr]
(@SourceStr varchar(8000))--源字符串
RETURNS @table table(list varchar(40) )
AS
BEGIN
select @sourcestr = replace(@sourcestr,';',',')
select @sourcestr = replace(@sourcestr,'\',',')
select @sourcestr = replace(@sourcestr,'/',',')
select @sourcestr = replace(@sourcestr,'.',',')
-- select @sourcestr = replace(@sourcestr,' ',',')
--declare @OutStr varchar(200)
if charindex(',',@sourcestr)>0
begin
declare @i int
declare @n int
set @i=1
while charindex(',',@sourcestr,@i)>0
begin
set @n=charindex(',',@sourcestr,@i)
insert into @table values(substring(@sourcestr,@i, @n-@i) ) &nb