求一sql语句 - MS-SQL Server / 基础类
表
id bh
1 10
2 11
3 12
4 15
5 16
6 22
7 25
8 26
9 27
10 28
将bh按连续分段出来返回字符串:
10~12,15~16,22,25~28
SQL code:
declare @t table(num int)
insert into @t select 1
union all select 2
union all select 3
union all select 4
union all select 5
union all select 12
union all select 17
union all select 18
union all select 19
union all select 20
union all select 25
select
rtrim(a.num)+(case when min(b.num)!=a.num then '-'+rtrim(min(b.num)) else '' end)
from
(select t.num from @t t where not exists(select 1 from @t where num=t.num-1)) a,
(select t.num from @t t where not exists(select 1 from @t where num=t.num+1)) b
where
a.num<=b.num
group by a.num
-------------------------
1-5
12
17-20
25
*/
{{
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
我要得到一个字符串如:
sdfk|||sgts
sdfsfd|||rgreg
wrfw|||sefw
就是要得到|||后面的字符串,有什么函数吗?怎么用呢?谢谢!
SQL code:
select
right(col,len(col)-charindex('|||',col)-2)
f ......
--drop table #T1
--drop table #T2
create Table #T1(ID int,
QueryID nvarchar(20),
ResultID1 nvarchar(20),
ResultID2 nvarchar(20))
create Table #T2(SortNo int,
QueryID nvarchar(20),
ResultID1 nv ......
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......