以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 表达式 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=74403) |
-- 作者:阿福 -- 发布时间:2015/9/10 10:18:00 -- 表达式 cmd.CommandText = "select sys_user, year(日期) as 日期_年, month(日期) as 日期_月, sum(头数) as 日龄_0至30, sum(头数1) as 日龄_30至60, sum(头数2) as 日龄_60至90, sum(头数3) as 日龄_90至120, " & _ "sum(头数4) As 日龄_120至150, sum(头数5) As 日龄_150至180, sum(头数6) As 日龄_180至210, sum(头数7) As 日龄_210至240, sum(头数8) As 日龄_240至270, sum(头数9) As 日龄_270至300, count(头数10) as 母猪, count(头数11) as 公猪 f rom " & _ "(Select sys_user, 日期, 头数, 0 As 头数1, 0 As 头数2, 0 As 头数3, 0 As 头数4, 0 As 头数5, 0 As 头数6, 0 As 头数7, 0 As 头数8, 0 As 头数9, 0 as 头数10, 0 as 头数11 f rom {死亡淘汰} where [肉猪日龄_低]= 0 u nion all " & _ "select sys_user, 日期, 0, 头数, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 f rom {死亡淘汰} where [肉猪日龄_低]= 30 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 头数, 0, 0, 0, 0, 0, 0, 0, 0, 0 f rom {死亡淘汰} where [肉猪日龄_低]= 60 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 头数, 0, 0, 0, 0, 0, 0, 0, 0 f rom {死亡淘汰} where [肉猪日龄_低]= 90 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 头数, 0, 0, 0, 0, 0, 0, 0 f rom {死亡淘汰} where [肉猪日龄_低]= 120 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 头数, 0, 0, 0, 0, 0, 0 f rom {死亡淘汰} where [肉猪日龄_低]= 150 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 头数, 0, 0, 0, 0, 0 f rom {死亡淘汰} where [肉猪日龄_低]= 180 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 0, 头数, 0, 0, 0, 0 f rom {死亡淘汰} where [肉猪日龄_低]= 210 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 0, 0, 头数, 0, 0, 0 f rom {死亡淘汰} where [肉猪日龄_低]= 240 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 0, 0, 0, 头数, 0, 0 f rom {死亡淘汰} where [肉猪日龄_低]= 270 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 编号, 0 f rom {死亡淘汰} where 猪只类型 = \'母猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 编号 f rom {死亡淘汰} where 猪只类型 = \'公猪\' ) " & _ "as a where [sys_user]=\'" & user.Name & "\' and 日期 between \'" & d1 & "\' and \'" & d2 & "\' group by sys_user, year(日期), month(日期) order by year(日期), month(日期) " dt = cmd.ExecuteReader 请问老师,上面代码的错误提示说:黄色部分为编译错误,应该表达式,该怎么改
|
-- 作者:大红袍 -- 发布时间:2015/9/10 11:00:00 -- 最后两列,不要用0表示,用空字符如 \'\' |
-- 作者:阿福 -- 发布时间:2015/9/10 11:43:00 -- 这样不行 "select sys_user, 日期, "", "", "", "", "", "", "", "", "", "", 编号, "" f rom {死亡淘汰} where 猪只类型 = \'母猪\' u nion all " & _ "select sys_user, 日期, "", "", "", "", "", "", "", "", "", "", "", 编号 f rom {死亡淘汰} where 猪只类型 = \'公猪\' ) " & _
|
-- 作者:大红袍 -- 发布时间:2015/9/10 11:57:00 -- 关键是第一行啊
"(Select sys_user, 日期, 头数, 0 As 头数1, 0 As 头数2, 0 As 头数3, 0 As 头数4, 0 As 头数5, 0 As 头数6, 0 As 头数7, 0 As 头数8, 0 As 头数9, \'\' as 头数10, \'\' as 头数11 f rom {死亡淘汰} where [肉猪日龄_低]= 0 u nion all " & _ |
-- 作者:阿福 -- 发布时间:2015/9/10 12:16:00 -- "(Select sys_user, 日期, 头数, 0 As 头数1, 0 As 头数2, 0 As 头数3, 0 As 头数4, 0 As 头数5, 0 As 头数6, 0 As 头数7, 0 As 头数8, 0 As 头数9, \'\' as 头数10, \'\' as 头数11 f rom {死亡淘汰} where [肉猪日龄_低]= 0 u nion all " & _ "select sys_user, 日期, 0, 头数, 0, 0, 0, 0, 0, 0, 0, 0, \'\', \'\' f rom {死亡淘汰} where [肉猪日龄_低]= 30 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 头数, 0, 0, 0, 0, 0, 0, 0, \'\', \'\' f rom {死亡淘汰} where [肉猪日龄_低]= 60 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 头数, 0, 0, 0, 0, 0, 0, \'\', \'\' f rom {死亡淘汰} where [肉猪日龄_低]= 90 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 头数, 0, 0, 0, 0, 0, \'\', \'\' f rom {死亡淘汰} where [肉猪日龄_低]= 120 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 头数, 0, 0, 0, 0, \'\', \'\' f rom {死亡淘汰} where [肉猪日龄_低]= 150 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 头数, 0, 0, 0, \'\', \'\' f rom {死亡淘汰} where [肉猪日龄_低]= 180 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 0, 头数, 0, 0, \'\', \'\' f rom {死亡淘汰} where [肉猪日龄_低]= 210 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 0, 0, 头数, 0, \'\', \'\' f rom {死亡淘汰} where [肉猪日龄_低]= 240 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 0, 0, 0, 头数, \'\', \'\' f rom {死亡淘汰} where [肉猪日龄_低]= 270 and 猪只类型=\'肉猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 编号, \'\' f rom {死亡淘汰} where 猪只类型 = \'母猪\' u nion all " & _ "select sys_user, 日期, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \'\', 编号 f rom {死亡淘汰} where 猪只类型 = \'公猪\' ) " & _ 这样不行
|
-- 作者:大红袍 -- 发布时间:2015/9/10 12:24:00 -- 什么不行,数据表发上来测试,不可能不行。 |
-- 作者:阿福 -- 发布时间:2015/9/10 14:16:00 -- 数据表怎样才能发上来? |
-- 作者:Hyphen -- 发布时间:2015/9/10 14:55:00 -- 上传测试项目 |