sql问题,100分的 - MS-SQL Server / 基础类
http://topic.csdn.net/u/20100520/16/1b999f17-1c5a-4901-b264-633436347b5f.html?54908
帮顶给分不?
sybase不支持自定义函数,没办法
你可以参考临时表和游标的方法试试
ddd
--游标
use sybase
create table tb
(
Id int,
value varchar(50),
)
insert into tb values('1','aa')
insert into tb values('1','bb')
insert into tb values('2','aaa')
insert into tb values('2','bbb')
insert into tb values('2','ccc')
go
declare @AA varchar(50)
declare @BB varchar(50)
declare @CC varchar(50)
declare my_cursor cursor for select value from tb
open my_cursor
fetch next from my_cursor into @AA
fetch next from my_cursor into @BB
select Id ,value=(@AA+','+@BB ) from tb where value=@BB
fetch next from my_cursor into @AA
fetch next from my_cursor into @BB
fetch next from my_cursor into @CC
select Id,value=(@AA+','+@BB+','+@CC) from tb where value=@AA
close my_cursor
deallocate my_cursor
drop table tb
已经测试过了,可用,楼主可以试试.
sybase啊,我自建的数据库中测试的,刚学,是不是我搞错了....
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......