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

数段,查询问题!速度来吧
表A
name xbegin xend 
哈 1830250 1830252

查出一下结果

name xbegin  
哈 1830250
哈 1830251
哈 1830252



------解决方案--------------------
SQL code

select * from 表A where name='哈'

------解决方案--------------------
SQL code

declare @表A table (name varchar(2),xbegin int,xend int)
insert into @表A
select '哈',1830250,1830252

select name,xbegin=a.xbegin+number 
from @表A  a left join 
(select number from master..spt_values where type='p') b on 1=1
where number <=xend-xbegin
/*
name xbegin
---- -----------
哈    1830250
哈    1830251
哈    1830252
*/

------解决方案--------------------
关联master..spt_values做数据。。。
------解决方案--------------------
SQL code

select name,xbegin=a.xbegin+number from 表A a 
left join (select number from master..spt_values where type='p') b on 1=1
where number <=xend-xbegin

------解决方案--------------------
SQL code
declare @表A table (name varchar(2),xbegin int,xend int)
insert into @表A
select '哈',1830250,1830252

 
select s.name,s.xbegin+number as xbegin from @表A s 
join master..spt_values 
 on 1=1 where number<=xend-xbegin and type='p'





(1 行受影响)
name xbegin
---- -----------
哈    1830250
哈    1830251
哈    1830252

(3 行受影响)