当前位置: 代码迷 >> PB >> 请问PB里的SQL语句写法
  详细解决方案

请问PB里的SQL语句写法

热度:85   发布时间:2016-04-29 08:17:57.0
请教PB里的SQL语句写法
在查询分析器中,执行以下行转列的存储过程,能得出行转列的结果.
CREATE PROCEDURE report_cw AS
begin
declare @s nvarchar(4000)
set @s=''
Select @[email protected]+','+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 [email protected]+' 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里写,不用调用存储过程([email protected]!)
[email protected],如何写?


------解决方案--------------------
那存储程里就不要写成:
exec(@s)

改写成:
select @s

然后用该存储过程创建一个DW,再retrieve() 再getitemstring()
  相关解决方案