以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- sql语句 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=130713) |
||||
-- 作者:xxfoxtable -- 发布时间:2019/1/29 22:25:00 -- sql语句 s elect (S elect sum(收入金额) from {收入} where 日期>=#" & Date.Today.AddDays(-30) & "# and 日期<=#" & Date.Today &"#) As 收入,(S elect sum(费用金额) from {费用} where 日期>=#" & Date.Today.AddDays(-30) & "# and 日期<=#" & Date.Today &"#) As 费用,收入-费用 as 利润
这样的SQL语句 ,怎么合成不报错?
|
||||
-- 作者:有点蓝 -- 发布时间:2019/1/29 22:53:00 -- "Select 收入,费用,收入-费用 As 利润 from (Select sum(收入金额) from {收入} where 日期>=#" & Date.Today.AddDays(-30) & "# and 日期<=#" & Date.Today & "#) As 收入,(S elect sum(费用金额) from {费用} where 日期>=#" & Date.Today.AddDays(-30) & "# and 日期<=#" & Date.Today & "#) As 费用) as a"
|
||||
-- 作者:xxfoxtable -- 发布时间:2019/1/30 16:04:00 -- "Select 收入,费用,收入-费用 As 利润 from ((Select sum(收入金额) from {收入} where 日期>=#" & Date.Today.AddDays(-30) & "# and 日期<=#" & Date.Today & "#) As 收入,(S elect sum(费用金额) from {费用} where 日期>=#" & Date.Today.AddDays(-30) & "# and 日期<=#" & Date.Today & "#) As 费用) as a"我这样写报错
|
||||
-- 作者:有点蓝 -- 发布时间:2019/1/30 17:35:00 -- 照抄2楼,不要画蛇添足 |
||||
-- 作者:xxfoxtable -- 发布时间:2019/1/30 17:48:00 -- 按二楼的真的不行,提示未指定错误!感觉二楼缺个左括号,写上也不行 [此贴子已经被作者于2019/1/30 17:48:27编辑过]
|
||||
-- 作者:有点甜 -- 发布时间:2019/1/30 21:53:00 -- 1、你直接设置还是写代码的?
2、2楼的是写代码的,你最后msgbox弹出合成的值看一下。在sql测试窗口测试,看报什么错。
3、做个例子发上来测试。 |
||||
-- 作者:xxfoxtable -- 发布时间:2019/1/30 22:05:00 --
|
||||
-- 作者:有点甜 -- 发布时间:2019/1/30 22:44:00 -- Dim cmd As new sqlcommand cmd.CommandText="select top 1 (Select sum(收入金额) from {收入} where 日期>=#" & Date.Today.AddDays(-30) & "# and 日期<=#" & Date.Today & "#) As 收入,(Select sum(费用金额) from {费用} where 日期>=#" & Date.Today.AddDays(-30) & "# and 日期<=#" & Date.Today &"#) As 费用," & _ "收入-费用 as 利润 from {收入}" Tables("窗口1_table1").DataSource =cmd.ExecuteReader Tables("窗口1_table1").AutoSizeCols |