declare @s varchar(8000)
declare @i int
set @i=1
set @s='select comm_createdby,month(comm_createddate) as cmonth '
while @i<31
begin
set @s=@s+',(case day(comm_createddate) when '+cast(@i as varchar(10))+' then count(day(comm_createddate)) else 0 end) as '''+cast(@i as varchar(10))+''''+char(10)
set @i=@i+1
end
exec(@s+'from communication where comm_deleted is null group by day(comm_createddate),month(comm_createddate),comm_createdby')
declare @i int
set @i=1
set @s='select comm_createdby,month(comm_createddate) as cmonth '
while @i<31
begin
set @s=@s+',(case day(comm_createddate) when '+cast(@i as varchar(10))+' then count(day(comm_createddate)) else 0 end) as '''+cast(@i as varchar(10))+''''+char(10)
set @i=@i+1
end
exec(@s+'from communication where comm_deleted is null group by day(comm_createddate),month(comm_createddate),comm_createdby')
解决方案 »
- 请教使用restore命令
- 【T-MAC学习笔记10之--数据修改之插入数据,更新数据,删除数据】
- 感觉挺难的汇总问题
- 附加数据库后,数据库里的表打不开,但是用查询分析器可以查询出部分数据
- 怎样在查询中实现多级小记和汇总?(在线等待)
- 主机密码改了 SQLserver启动不了,怎么办?
- sqlstate=37000是什么错误
- 一张照片存在image类型的字段中,如何用update 清除照片
- 公司的水费管理系统用的是Foxpro数据库,但是作者把库文件加密了(用VF找开该库的时候,提示找不到一个.prg文件)。请问怎样把这个库解开呢?
- 救命呀delphi如何浏览sql server7.0的image字段
- 怎么使用全文检索,就是Microsoft Search 服务到哪里去找呀,找都找不到,急
- KCSW(库存事务)触发器怎么改?
as
declare @s varchar(8000)
declare @i int
set @i=1
set @s='select comm_createdby,month(comm_createddate) as cmonth '
while @i <31
begin
set @s=@s+',(case day(comm_createddate) when '+cast(@i as varchar(10))+' then count(day(comm_createddate)) else 0 end) as '''+cast(@i as varchar(10))+''''+char(10)
set @i=@i+1
end
exec(@s+'from communication where comm_deleted is null group by day(comm_createddate),month(comm_createddate),comm_createdby')
再
INSERT INTO TB EXEC()CREATE VIEW VIEW_TB
AS
SELECT * FROM TB
再
INSERT INTO TB EXEC()CREATE VIEW VIEW_TB
AS
SELECT * FROM TB
[/Quote]除了创建一个与查询结果一样的表结构,还有什么好的方法吗?谢谢