日期:2014-05-18  浏览次数:20536 次

视图中如何自动根据要求生成一个列,并填充数据?
有个表格,里面有字段
station(园区名)
flat_id(楼号)
room_id(房间号)
bed_num(床位数)

希望能根据这张表中床位数自动生成一个视图,视图中包括
station(园区名)
flat_id(楼号)
room_id(房间号)
bed_id(床位号)

其实也就是根据床位数,生成一张表,里面有具体的床位号,不知道视图是否可以实现,如果不行,触发器可以实现吗?怎么实现?

非常感谢

------解决方案--------------------
select top 100 identity(int,1,1) as id into #tmp from sysobjects,syscolumns

select station,flat_id,room_id,x.id as bed_id
from tab t
join #tmp x on x.id <= t.bed_num

drop table #tmp
------解决方案--------------------
select station,flat_id,room_id,x.id as bed_id
from tab t
join (select 1 id union select 2 union select 3 union select 4 union select 5 union select 6) x on x.id <= t.bed_num