请教PB里的SQL语句写法

sunfor 2012-05-03 10:39:45
在查询分析器中,执行以下行转列的存储过程,能得出行转列的结果.
CREATE PROCEDURE report_cw AS
begin
declare @s nvarchar(4000)
set @s=''
Select @s=@s+','+quotename([type2])+'=max(case when [type2]='+quotename([type2],'''')+' then [total] else 0 end)' from TB1 group by [type2]
set @s='select [name],sum(total) as total'+@s+' from TB1 group by name order by name'
exec(@s)
end
GO

@s的值如下:(其中长度有1000多字符左右)
select [name],sum(total) as total,[差旅费]=max(case when [type2]='差旅费' then [total] else 0 end),[接待费]=max(case when [type2]='接待费' then [total] else 0 end),[礼品]=max(case when [type2]='礼品' then [total] else 0 end),[设计费]=max(case when [type2]='设计费' then [total] else 0 end),[外包费]=max(case when [type2]='外包费' then [total] else 0 end),[赠送]=max(case when [type2]='赠送' then [total] else 0 end),[准备金]=max(case when [type2]='准备金' then [total] else 0 end) ...... from TB1 group by name order by name

如果我把上面的存储过程,在PB里写,不用调用存储过程(试了多次得不了@S的值!)
想得到上面的@s的字符串值,如何写?
...全文
127 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wag_enu 2012-05-04
  • 打赏
  • 举报
回复
最好是写成 select @s as s

这样,在getitemstring() 的时候就可以写 dw.getitemstring(1, 's')
wag_enu 2012-05-04
  • 打赏
  • 举报
回复
那存储程里就不要写成:
exec(@s)

改写成:
select @s

然后用该存储过程创建一个DW,再retrieve() 再getitemstring()

1,076

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧