日期:2014-05-17 浏览次数:20472 次
create function [dbo].[GetUserName](@ColunmValue nvarchar(50))
returns varchar(8000)
as
begin
DECLARE @RetVal varchar(8000)
SET @RetVal = ''
select @RetVal = name + ',' + @RetVal from [Dealer]
where id in (@ColunmValue)
IF LEN(@RetVal) > 0
SET @RetVal = LEFT(@RetVal, LEN(@RetVal) - 1)
return (@Retval)
end
create function [dbo].[GetUserName](@ColunmValue nvarchar(50))
returns varchar(8000)
as
begin
DECLARE @RetVal varchar(8000)
SET @RetVal = ''
select @RetVal = name + ',' + @RetVal from [Dealer]
where id in (@ColunmValue) --这儿写的不对,如果你传了个"1,2,3",会把"1,2,3"转化成整型,会报错的
IF LEN(@RetVal) > 0
SET @RetVal = LEFT(@RetVal, LEN(@RetVal) - 1)
return (@Retval)
END
go
--改成:
create function [dbo].[GetUserName](@ColunmValue nvarchar(50))
returns varchar(8000)
as
begin
DECLARE @RetVal varchar(8000)
SET @RetVal = ''
DECLARE @temp TABLE(NAME NVARCHAR(255))
INSERT @temp
EXEC('SELECT name FROM [Dealer] where id in ('+ @ColunmValue +')')
select @RetVal = name + ',' + @RetVal from @temp
IF LEN(@RetVal) > 0
SET @RetVal = LEFT(@RetVal, LEN(@RetVal) - 1)
return (@Retval)
END