请教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的字符串值,如何写?
...全文
128 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()
存储过程的安全及性能优化 存储过程分类  系统存储过程  自定义存储过程  SQL Server使用者编写的存储过程  扩展存储过程  动态链接库(DLL)函数的调用看,主要用于客户端和服务器端之间进行通信  exec master..xp_cmdshell 'dir *.exe' -- 执行目录命令查询[sql2005\sql2008]  exec master..xp_fixeddrives --列出硬盘分区各自可用空间  xp_regwrite根键,子键,值名,值类型,值【sql2008拒绝访问】  写入注册表,例如:  exec master..db.xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\run','TestValueName','reg_sz','hello'  xp_regdeletevalue 根键,子键,值名【sql2008拒绝访问】  删除注册表某个值  xp_regdeletekey键,值【sql2008拒绝访问】  删除该键下包括的所有值 xp_cmdshell语法  xp_cmdshell {'command_string'} [,no_output]  command_string是在操作系统命令行解释器上执行的命令字符串。command_string数据类型为varchar(255)或者nvarchar(4000),没有默认值  no_output为可选参数,可以控制是否想客户端返回信息  该存储过程一般情况下被禁用的,需要手动开启使用,如下:  exec sp_configure 'show advanced options',1  go   reconfigure  go   exec sp_configure 'xp_cmdshell',1—1表示启用,0表示禁用  go   reconfigure  go 删除xp_cmdshell SQL SERVER200删除xp_cmdshell use master exec sp_dropextendedproc 'xp_cmdshell' go SQL SERVER2005以上禁用xp_cmdshell,但不能删除掉 exec sp_configure 'xp_cmdshell',0 —1表示启用,0表示禁用  go reconfigure --让sp_configurre立即生效  go  exec sp_configure 'show advanced options',0  go   reconfigure  go --注意:SQL SERVER2008考虑安全性很多存储过程直接被拒绝访问 恢复/启用扩展存储过程 SQLServer2000 use master exec sp_addextendedproc xp_cmdshell,'xplog70.dll' go SQL Server2005或SQL Server2008启用xp_cmdshell  exec sp_configure 'show advanced options',1  go   reconfigure  go   exec sp_configure 'xp_cmdshell',1—1表示启用,0表示禁用  go   reconfigure  go 扩展存储过程的定义  扩展存储过程是SQL Server中的另一类存储过程,它是以其它语言编写的外部程序,是以动态链接库(DLL)形式存储在服务器上,最终SQLServer就可以动态加载并执行它们  编写好后使用SQLServer的固定角色sysadmin注册该扩展存储过程,并将执行权限授予其它用户,这个扩展存储过程只能添加到master数据库。  在编写扩展存储过程中可能要用到某些系统存储过程,这些系统存储过程如下: 利用OLE自动化存储过程调用dll 1.创建类库程序集 namespace PB_ExtendProcedure { public class ExtendProcedure { public string SayHi() { return "hello world"; } } } 2.生成动态链接库并注册到系统中 2.1.生成动态链接库使用VS2010命令行工具 使用sn命令生成一个强命名文件: sn -k he

1,079

社区成员

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

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