I want to join a table function and a table.Is it possible?How?
table (Id,Title)
function (table1.Id) : returns (Id,Describ1,Describ2)
Resault should be: (Table1.Id,Title,Describ1,Describ2)
Use the following query..
Select Table.Id, Table.Title, Fun.Id, Fun.Descib1, Fun.Descib2
From Table
Join function(someid) as Fun on Fun.ID = Table.ID
|||For SQL Server 2005, use the cross apply operator as below.
For SQL Server 2000, there's no easy way (can be done using a cursor)
create table mytable(Id int,Title varchar(10))
go
create function dbo.myfunction(@.Id int)
returns @.retTab table(Id int ,Describ1 varchar(10),Describ2 varchar(10))
as
begin
insert into @.retTab(Id,Describ1,Describ2)
select @.Id,'Describ1','Describ2'
return
end
go
select mytable.Id, mytable.Title, Fn.Describ1, Fn.Describ2
from mytable
cross apply dbo.myfunction(Id) as Fn
No comments:
Post a Comment