Dim Sum3 As string = "select Prod_ID," & Chr(13) & Chr(10)
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -isnull(Prod_Number,0) else isnull(Prod_Number,0) end) AS 'Prod_Number'," & Chr(13) & Chr(10)
Sum3 = Sum3 + "sum(case when d.billtype2=16 then 0 else isnull(DisMoney,0) end) AS 'DisMoney1'," & Chr(13) & Chr(10)
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -isnull(DisMoney,0) else 0 end) AS 'DisMoney2'," & Chr(13) & Chr(10)
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -isnull(DisMoney,0) else isnull(DisMoney,0) end) AS 'DisMoney'," & Chr(13) & Chr(10)
Sum3 = Sum3 + "sum(case when d.billtype2=16 then 0 else isnull(CostMoney,0) end) AS 'CostMoney1'," & Chr(13) & Chr(10)
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -isnull(CostMoney,0) else 0 end) AS 'CostMoney2'," & Chr(13) & Chr(10)
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -isnull(CostMoney,0) else isnull(CostMoney,0) end) AS 'CostMoney'," & Chr(13) & Chr(10)
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -(isnull(dismoney,0)-isnull(costmoney,0)) else (isnull(dismoney,0)-isnull(costmoney,0)) end) ProfitMoney," & Chr(13) & Chr(10)
Sum3 = Sum3 + "'零售'AS 'type','最近1个月' AS 'month'" & Chr(13) & Chr(10)
Sum3 = Sum3 + "from ListSale A" & Chr(13) & Chr(10)
Sum3 = Sum3 + "left join (select autoid,unit_id,billtype,billdate,s_Syb from masterbill) b on a.bill_id=b.autoid" & Chr(13) & Chr(10)
Sum3 = Sum3 + "left join (select s_id from units) c on b.unit_id=c.s_id" & Chr(13) & Chr(10)
Sum3 = Sum3 + "left join (select billtype billtype2,billname from billtype) d on b.billtype=d.billtype2" & Chr(13) & Chr(10)
Sum3 = Sum3 + "left join (select s_id,u_Code,u_Name from product) e on a.prod_id=e.s_id" & Chr(13) & Chr(10)
Sum3 = Sum3 + "where b.s_Syb = 0 and d.billtype2 in ('15','16') and (b.billdate >= CONVERT(varchar(100),DateAdd(m,-1,GETDATE()), 23) and b.billdate <= CONVERT(varchar(100), GETDATE(), 23))" & Chr(13) & Chr(10)
Sum3 = Sum3 + "And e.u_Code in ('240325','240461','244610','243095','246364','248180','248599','013430','012947','115398')" & Chr(13) & Chr(10)
Sum3 = Sum3 + "GROUP BY Prod_ID" & Chr(13) & Chr(10)
Dim dst As WinForm.DataList = e.Form.Controls("DataList1")
Dim cmd As New SQLCommand
cmd.CommandText = "" & Sum3 & ""
cmd.C
dst.DataTable = cmd.ExecuteReader()
dst.Build()
以上代码正常运行,请问为什么SQL语句要那么麻烦一行一行的拆开再进行组合