create table t(col varchar(20))
insert t
select 'A' union all
select 'B' union all
select 'C' union all
select 'D'
go
create function f_he(@col varchar(20))
returns varchar(50)
as
begin
declare @sql varchar(50)
set @sql=''
select @sql=@sql+'-'+col from t where col>=@col
return(stuff(@sql,1,1,''))
end
goselect dbo.f_he('A')drop function f_he
drop table t--------------------------------------------------
A-B-C-D(所影响的行数为 1 行)
insert t
select 'A' union all
select 'B' union all
select 'C' union all
select 'D'
go
create function f_he(@col varchar(20))
returns varchar(50)
as
begin
declare @sql varchar(50)
set @sql=''
select @sql=@sql+'-'+col from t where col>=@col
return(stuff(@sql,1,1,''))
end
goselect dbo.f_he('A')drop function f_he
drop table t--------------------------------------------------
A-B-C-D(所影响的行数为 1 行)
解决方案 »
- Select 输出数值型数据问题
- 怎样根据一个存储过程返回的值,生成一个游标
- 怎样查找表中的第N条记录?
- 请问怎么把“2005年3月7日”转换为datetime类型?多谢
- convert(char(20),'1/4/2005 09:51:25:276',101),正确的写法是什么?
- [数据传输](一共400分)中心服务器采用TCP/IP和轮巡方式从N(N<20)个二级数据取得数据!
- 是不是企业版SQL SERVER 必须安装在NT上?
- 在存储过程里使用游标速度会慢吗?有没有提高速度的好法子?
- 如何使某菜单不可见
- sql server中的系统存储过程问题,谢谢
- 关于硬盘分区的问题
- 【该问题乃水月儿自来SQL版块遇到难度最大的查询问题!红尘GG及各门各派高手请务必帮忙~~~~】
--建立测试数据
declare @t table(a varchar(5),b varchar(5))
insert @T
select 'A','TY' UNION ALL
select 'B','88' UNION ALL
select 'B','KEKE' UNION ALL
select 'C','tt' UNION ALL
select 'D','gg' union all
select 'C','www' union all
select 'D','hh'--实现按规定的规则排序
select * from @t order by charindex(a,'A-C-D-B')/*结果:
a b
---------
A TY
C tt
C www
D gg
D hh
B KEKE
B 88 */