sum(case goodstype when '产品1' then am else null end,0 ) as '产品1上午',sum(case goodstype when '产品1' then pm else null end,0) as '产品1下午'),");
我的意思是如果是产品1,那么am就为产品1上午,pm为产品1下午,上面这句是错的,请问我应该怎么写呢谢谢~~~~
我的意思是如果是产品1,那么am就为产品1上午,pm为产品1下午,上面这句是错的,请问我应该怎么写呢谢谢~~~~
解决方案 »
- 前端,后端?
- 安装项目如何获取用户界面的复选框?解决即给分!!!!
- 国外类似于 csdn 这样的人气较高论坛有哪些?
- 用C#能否编写静态链接库?或是C#编写的动态链接库能否实现静态库的功能。
- C#调用COM组件时的结构类型数据封送问题,报PInvoke 签名错误
- 如何在C#程序中执行“Create Database”SQL语句来创建数据库?
- C#制作字典
- 请大家帮帮忙我在网站下载了C#做的ASP.NET网站程序,但老是报错错误如下,不知为何?
- Visual Studio 为编译的DLL自动生成一个版本号...
- 请问~~~
- 求助:用C#怎样抓取webservice的 soap 数据包
- c# 输入一部分就显示全部
sum(case when goodstype='产品1' then pm else 0 end) as 产品1下午,
提示)附近有错误,奇怪,求大家帮我更正下,谢谢
,
sum(case goodstype when '产品1' then pm else 0 end ) as '产品1下午'
sum(case goodstype when '产品1' then am else 0 end ) as '产品1上午',
sum(case goodstype when '产品1' then pm else 0 end) as '产品1下午'
FROM TB
sum(case goodstype when '产品1' then pm else 0 end) as 产品1下午
然后,你需要这样做,as后的别名不能用','是用于值的:
"sum(case when goodstype = '"+strth+"' then am else null end) as " + rgth1 + "am,sum(case when goodstype = '" + strth + "' then pm else null end) as " + rgth1 + "pm,"
"sum(case when goodstype = '"+strth+"' then am else 0 end) as " + rgth1 + "am,sum(case when goodstype = '" + strth + "' then pm else 0 end) as " + rgth1 + "pm,"如果你的goodstype的类型为NChar/NVarchar,那么你的 ='"+strth+"' -> =N'"+strth+"',也就是变量的值前加个N。
create table tt
( [name] varchar(20),[type] varchar(50),[date] varchar(20),[am] int,[pm] int)
insert into tt select 'A','产品1','2009-04-03',5,6
union all select 'A','产品2','2009-04-03',4,1
union all select 'A','产品3','2009-04-03',7,1
union all select 'B','产品2','2009-04-03',3,1
union all select 'B','产品1','2009-04-03',1,4
select * from ttdeclare @sql varchar(5000)
select @sql=isnull(@sql+',','')+'max(case when type='''+type+''' then am else 0 end) as ['+type+'上午],max(case when type='''+type+''' then pm else 0 end) as ['+type+'下午]'
from tt group by type
exec('select [name] 市场名称,'+@sql+',[date] 送货日期 from tt group by [name],[date]')--proc
create proc up_GetView
as
declare @sql varchar(5000)
select @sql=isnull(@sql+',','')+'max(case when type='''+type+''' then am else 0 end) as ['+type+'上午],max(case when type='''+type+''' then pm else 0 end) as ['+type+'下午]'
from tt group by type
exec('select [name] 市场名称,'+@sql+',[date] 送货日期 from tt group by [name],[date]')--执行存储过程
exec up_GetView
,
sum(case goodstype when '产品1' then pm else 0 end ) as '产品1下午'支持此解