日期:2014-05-19  浏览次数:20569 次

函数返回多个值?
select   *from   test,lastDateAddr( '2007-04-01 ', '2007-05-01 ',test.name)   lastStr

这是错误的,正确的该如何写?

------解决方案--------------------
lastDateAddr 是什么函数?
标量?表值?
------解决方案--------------------
select *,dbo.lastDateAddr( '2007-04-01 ', '2007-05-01 ',test.name) lastStr from test
------解决方案--------------------
他说的是函数,返回多个值,不是少了dbo.的问题吧
------解决方案--------------------
只能说你的函数写错了

没办法像你想象的那样调用

------解决方案--------------------
你可以写个函数:

create function lastDateAddr1(@date1 datetime,@date2 datetime)
returns table
as
return(
select mmst501.cust_no,max(mmst501.deliv_date) deliv_date,mmst502.mtr_no,mmst012.deliv_addr
from mmst501,mmst502,mmst012
where mmst502.mtr_no in (select name from test)
and mmst501.deliv_no=mmst502.deliv_no
and mmst501.deliv_date between @date1 and @date2
and mmst502.line_no=mmst012.line_no
and mmst501.deliv_date=mmst012.deliv_date
and mmst502.mtr_no=mmst012.mtr_no
group by mmst501.cust_no,mmst502.mtr_no,mmst012.deliv_addr
)

go

然后这么调用
select * from lastDateAddr1( '2007-04-01 ', '2007-05-01 ') as t

------解决方案--------------------
lastDateAddr(@date1 datetime,@date2 datetime,test1.a)

这里参数什么能是test1.a,一个字段呢?
------解决方案--------------------
create function dddd()
returns @t table(id int)
as
begin
insert @t select 1 union select 2
return
end
go
select * from dddd()
drop function dddd