自定义函数
declare @String varchar(100)
select @string=''
select @string=@string+','+other from B where Id=@intputID
Return @string
declare @String varchar(100)
select @string=''
select @string=@string+','+other from B where Id=@intputID
Return @string
create function getstr(@id Nchar(10))
returns Nvarchar(2000)
as
begin
declare @str Nvarchar(2000)
set @str=N''
select @str=@str+N','+rtrim(other) from b
where id=@id
set @str=right(@str,len(@str)-1)
return @str
end
GO调用:
select a.id,a.name,dbo.getstr(a.id) as other from a
服务器: 消息 170,级别 15,状态 1,行 1
Line 1: Incorrect syntax near 'function'.
服务器: 消息 137,级别 15,状态 1,行 8
Must declare the variable '@id'.
服务器: 消息 178,级别 15,状态 1,行 10
A RETURN statement with a return status can only be used in a stored procedure.这是什么原因呢?
returns nvarchar(2000)
as
begin
declare @str nvarchar(2000)
set @str=N''
select @str=@str+N','+rtrim(other) from b where id=@id
-----------------------------------------^^^^改为你的表呀!
set @str=right(@str,len(@str)-1)
return @str
end
select a.id,a.name,b.other from a left join b on a.id=b.id
请把你的create贴出
returns Nvarchar(2000)
as
begin
declare @str Nvarchar(2000)
set @str=N''
select @str=@str+N','+rtrim(xm) from l_Zzzyjsryylb where jmsbh=@id
set @str=right(@str,len(@str)-1)
return @str
end我把这些直接放在查询分析器中,出错。
服务器: 消息 170,级别 15,状态 1,行 1
Line 1: Incorrect syntax near 'function'.
服务器: 消息 137,级别 15,状态 1,行 7
Must declare the variable '@id'.
服务器: 消息 178,级别 15,状态 1,行 9
A RETURN statement with a return status can only be used in a stored procedure.
可以呀