简体   繁体   English

Sybase查询:ASE中LIST()的替代方法

[英]Sybase Query : Alternative of LIST() in ASE

Could you please help me to find out below query in Sybase. 您能帮我在Sybase中找到以下查询吗?

I want a comma separated Row list. 我想要用逗号分隔的行列表。 There is one LIST() aggregate function but I can't use that because I am using Adaptive Server Enterprise. 有一个LIST()聚合函数,但是我不能使用它,因为我正在使用Adaptive Server Enterprise。

Is there any alternative query exist in Sybase to get LIST() ? Sybase中是否存在任何其他查询来获取LIST()?

For your reference: http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1604/doc/html/jcu1290709667623.html 供您参考: http : //infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1604/doc/html/jcu1290709667623.html

Thanks, Samrat Sarkar 谢谢,Samrat Sarkar

In ASE there are basically two options: (i) use a loop-based algorithm like a cursor (ii) use a little-known feature of the ASE UPDATE statement which can accumulate values over subsequent rows into a variable. 在ASE中,基本上有两种选择:(i)使用类似于游标的基于循环的算法(ii)使用ASE UPDATE语句的鲜为人知的功能,该功能可以将后续行中的值累加到变量中。

As for the latter, basically the idea is not updating any columns, but scanning through the rows like this: 对于后者,基本上的想法是不更新任何列,而是扫描像这样的行:

update Sales
set @cnt = @cnt + 1,
    @sum = @sum + Amount

For full details, see my book www.sypron.nl/ttr. 有关完整的详细信息,请参见我的书www.sypron.nl/ttr。

I have solved that with below technique, 我用下面的技术解决了

I have created one #temp table and loop through cursor and inserted comma separated value in #temp table. 我创建了一个#temp表并遍历游标,并在#temp表中插入了逗号分隔的值。

Now in main select query join with #temp table 现在在主选择查询中加入#temp表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM