为了账号安全,请及时绑定邮箱和手机立即绑定

关于sql server中的表函数?

关于sql server中的表函数?

哔哔one 2018-12-13 19:11:59
关于sql server中的表函数
查看完整描述

1 回答

?
慕神8447489

TA贡献1780条经验 获得超1个赞

这个问题用标致函数比较难,1楼调用标致函数的方法也是错误的,正确的方法应该是:
SELECT * FROM DBO.CaculateDailyTM()

我用游标实现 ,比较好理解:

create table tb1(zm char(8),sd datetime,ed datetime)
GO
insert into tb1 values('s1','1980-1-1','1980-2-1')
insert into tb1 values('s2','1992-2-1','1993-3-1')
GO
--建立测试数据

declare zm_cursor cursor fast_forward for select zm from tb1
declare @t1 datetime,@t2 datetime,@zm char(8)
declare @tb table(zm char(8),d datetime)
open zm_cursor
fetch next from zm_cursor into @zm
while @@fetch_status=0
begin
select @t1=sd,@t2=ed from tb1 where zm=@zm
while @t1<=@t2
begin
insert into @tb values(@zm,@t1)
set @t1=dateadd(day,1,@t1)
end
fetch next from zm_cursor into @zm
end
select * from @tb
close zm_cursor
deallocate zm_cursor

GO

DROP TABLE TB1

有问题HI我

这个问题用标致函数比较难,1楼调用标致函数的方法也是错误的,正确的方法应该是:
SELECT * FROM DBO.CaculateDailyTM()

我用游标实现 ,比较好理解:

create table tb1(zm char(8),sd datetime,ed datetime)
GO
insert into tb1 values('s1','1980-1-1','1980-2-1')
insert into tb1 values('s2','1992-2-1','1993-3-1')
GO
--建立测试数据

declare zm_cursor cursor fast_forward for select zm from tb1
declare @t1 datetime,@t2 datetime,@zm char(8)
declare @tb table(zm char(8),d datetime)
open zm_cursor
fetch next from zm_cursor into @zm
while @@fetch_status=0
begin
select @t1=sd,@t2=ed from tb1 where zm=@zm
while @t1<=@t2
begin
insert into @tb values(@zm,@t1)
set @t1=dateadd(day,1,@t1)
end
fetch next from zm_cursor into @zm
end
select * from @tb
close zm_cursor
deallocate zm_cursor

GO

DROP TABLE TB1

有问题HI我

这个问题用标致函数比较难,1楼调用标致函数的方法也是错误的,正确的方法应该是:
SELECT * FROM DBO.CaculateDailyTM()

我用游标实现 ,比较好理解:

create table tb1(zm char(8),sd datetime,ed datetime)
GO
insert into tb1 values('s1','1980-1-1','1980-2-1')
insert into tb1 values('s2','1992-2-1','1993-3-1')
GO
--建立测试数据

declare zm_cursor cursor fast_forward for select zm from tb1
declare @t1 datetime,@t2 datetime,@zm char(8)
declare @tb table(zm char(8),d datetime)
open zm_cursor
fetch next from zm_cursor into @zm
while @@fetch_status=0
begin
select @t1=sd,@t2=ed from tb1 where zm=@zm
while @t1<=@t2
begin
insert into @tb values(@zm,@t1)
set @t1=dateadd(day,1,@t1)
end
fetch next from zm_cursor into @zm
end
select * from @tb
close zm_cursor
deallocate zm_cursor

GO

DROP TABLE TB1

有问题HI我

这个问题用标致函数比较难,1楼调用标致函数的方法也是错误的,正确的方法应该是:
SELECT * FROM DBO.CaculateDailyTM()

我用游标实现 ,比较好理解:

create table tb1(zm char(8),sd datetime,ed datetime)
GO
insert into tb1 values('s1','1980-1-1','1980-2-1')
insert into tb1 values('s2','1992-2-1','1993-3-1')
GO
--建立测试数据

declare zm_cursor cursor fast_forward for select zm from tb1
declare @t1 datetime,@t2 datetime,@zm char(8)
declare @tb table(zm char(8),d datetime)
open zm_cursor
fetch next from zm_cursor into @zm
while @@fetch_status=0
begin
select @t1=sd,@t2=ed from tb1 where zm=@zm
while @t1<=@t2
begin
insert into @tb values(@zm,@t1)
set @t1=dateadd(day,1,@t1)
end
fetch next from zm_cursor into @zm
end
select * from @tb
close zm_cursor
deallocate zm_cursor

GO

DROP TABLE TB1

有问题HI我

这个问题用标致函数比较难,1楼调用标致函数的方法也是错误的,正确的方法应该是:
SELECT * FROM DBO.CaculateDailyTM()

我用游标实现 ,比较好理解:

create table tb1(zm char(8),sd datetime,ed datetime)
GO
insert into tb1 values('s1','1980-1-1','1980-2-1')
insert into tb1 values('s2','1992-2-1','1993-3-1')
GO
--建立测试数据

declare zm_cursor cursor fast_forward for select zm from tb1
declare @t1 datetime,@t2 datetime,@zm char(8)
declare @tb table(zm char(8),d datetime)
open zm_cursor
fetch next from zm_cursor into @zm
while @@fetch_status=0
begin
select @t1=sd,@t2=ed from tb1 where zm=@zm
while @t1<=@t2
begin
insert into @tb values(@zm,@t1)
set @t1=dateadd(day,1,@t1)
end
fetch next from zm_cursor into @zm
end
select * from @tb
close zm_cursor
deallocate zm_cursor

GO

DROP TABLE TB1

有问题HI我

这个问题用标致函数比较难,1楼调用标致函数的方法也是错误的,正确的方法应该是:
SELECT * FROM DBO.CaculateDailyTM()

我用游标实现 ,比较好理解:

create table tb1(zm char(8),sd datetime,ed datetime)
GO
insert into tb1 values('s1','1980-1-1','1980-2-1')
insert into tb1 values('s2','1992-2-1','1993-3-1')
GO
--建立测试数据

declare zm_cursor cursor fast_forward for select zm from tb1
declare @t1 datetime,@t2 datetime,@zm char(8)
declare @tb table(zm char(8),d datetime)
open zm_cursor
fetch next from zm_cursor into @zm
while @@fetch_status=0
begin
select @t1=sd,@t2=ed from tb1 where zm=@zm
while @t1<=@t2
begin
insert into @tb values(@zm,@t1)
set @t1=dateadd(day,1,@t1)
end
fetch next from zm_cursor into @zm
end
select * from @tb
close zm_cursor
deallocate zm_cursor

GO

DROP TABLE TB1

有问题HI我

这个问题用标致函数比较难,1楼调用标致函数的方法也是错误的,正确的方法应该是:
SELECT * FROM DBO.CaculateDailyTM()

我用游标实现 ,比较好理解:

create table tb1(zm char(8),sd datetime,ed datetime)
GO
insert into tb1 values('s1','1980-1-1','1980-2-1')
insert into tb1 values('s2','1992-2-1','1993-3-1')
GO
--建立测试数据

declare zm_cursor cursor fast_forward for select zm from tb1
declare @t1 datetime,@t2 datetime,@zm char(8)
declare @tb table(zm char(8),d datetime)
open zm_cursor
fetch next from zm_cursor into @zm
while @@fetch_status=0
begin
select @t1=sd,@t2=ed from tb1 where zm=@zm
while @t1<=@t2
begin
insert into @tb values(@zm,@t1)
set @t1=dateadd(day,1,@t1)
end
fetch next from zm_cursor into @zm
end
select * from @tb
close zm_cursor
deallocate zm_cursor

GO

DROP TABLE TB1

有问题HI我

这个问题用标致函数比较难,1楼调用标致函数的方法也是错误的,正确的方法应该是:
SELECT * FROM DBO.CaculateDailyTM()

我用游标实现 ,比较好理解:

create table tb1(zm char(8),sd datetime,ed datetime)
GO
insert into tb1 values('s1','1980-1-1','1980-2-1')
insert into tb1 values('s2','1992-2-1','1993-3-1')
GO
--建立测试数据

declare zm_cursor cursor fast_forward for select zm from tb1
declare @t1 datetime,@t2 datetime,@zm char(8)
declare @tb table(zm char(8),d datetime)
open zm_cursor
fetch next from zm_cursor into @zm
while @@fetch_status=0
begin
select @t1=sd,@t2=ed from tb1 where zm=@zm
while @t1<=@t2
begin
insert into @tb values(@zm,@t1)
set @t1=dateadd(day,1,@t1)
end
fetch next from zm_cursor into @zm
end
select * from @tb
close zm_cursor
deallocate zm_cursor

GO

DROP TABLE TB1

有问题HI我

这个问题用标致函数比较难,1楼调用标致函数的方法也是错误的,正确的方法应该是:
SELECT * FROM DBO.CaculateDailyTM()

我用游标实现 ,比较好理解:

create table tb1(zm char(8),sd datetime,ed datetime)
GO
insert into tb1 values('s1','1980-1-1','1980-2-1')
insert into tb1 values('s2','1992-2-1','1993-3-1')
GO
--建立测试数据

declare zm_cursor cursor fast_forward for select zm from tb1
declare @t1 datetime,@t2 datetime,@zm char(8)
declare @tb table(zm char(8),d datetime)
open zm_cursor
fetch next from zm_cursor into @zm
while @@fetch_status=0
begin
select @t1=sd,@t2=ed from tb1 where zm=@zm
while @t1<=@t2
begin
insert into @tb values(@zm,@t1)
set @t1=dateadd(day,1,@t1)
end
fetch next from zm_cursor into @zm
end
select * from @tb
close zm_cursor
deallocate zm_cursor

GO

DROP TABLE TB1

有问题HI我

这个问题用标致函数比较难,1楼调用标致函数的方法也是错误的,正确的方法应该是:
SELECT * FROM DBO.CaculateDailyTM()

我用游标实现 ,比较好理解:

create table tb1(zm char(8),sd datetime,ed datetime)
GO
insert into tb1 values('s1','1980-1-1','1980-2-1')
insert into tb1 values('s2','1992-2-1','1993-3-1')
GO
--建立测试数据

declare zm_cursor cursor fast_forward for select zm from tb1
declare @t1 datetime,@t2 datetime,@zm char(8)
declare @tb table(zm char(8),d datetime)
open zm_cursor
fetch next from zm_cursor into @zm
while @@fetch_status=0
begin
select @t1=sd,@t2=ed from tb1 where zm=@zm
while @t1<=@t2
begin
insert into @tb values(@zm,@t1)
set @t1=dateadd(day,1,@t1)
end
fetch next from zm_cursor into @zm
end
select * from @tb
close zm_cursor
deallocate zm_cursor

GO

DROP TABLE TB1

有问题HI我

这个问题用标致函数比较难,1楼调用标致函数的方法也是错误的,正确的方法应该是:
SELECT * FROM DBO.CaculateDailyTM()

我用游标实现 ,比较好理解:

create table tb1(zm char(8),sd datetime,ed datetime)
GO
insert into tb1 values('s1','1980-1-1','1980-2-1')
insert into tb1 values('s2','1992-2-1','1993-3-1')
GO
--建立测试数据

declare zm_cursor cursor fast_forward for select zm from tb1
declare @t1 datetime,@t2 datetime,@zm char(8)
declare @tb table(zm char(8),d datetime)
open zm_cursor
fetch next from zm_cursor into @zm
while @@fetch_status=0
begin
select @t1=sd,@t2=ed from tb1 where zm=@zm
while @t1<=@t2
begin
insert into @tb values(@zm,@t1)
set @t1=dateadd(day,1,@t1)
end
fetch next from zm_cursor into @zm
end
select * from @tb
close zm_cursor
deallocate zm_cursor

GO

DROP TABLE TB1



查看完整回答
反对 回复 2019-01-05
  • 1 回答
  • 0 关注
  • 456 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信