Foxtable(狐表)用户栏目专家坐堂 → SQL语句问题疑问


  共有16585人关注过本帖树形打印复制链接

主题:SQL语句问题疑问

帅哥哟,离线,有人找我吗?
migold
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
SQL语句问题疑问  发帖心情 Post By:2009/8/7 9:36:00 [只看该作者]

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语句要那么麻烦一行一行的拆开再进行组合


 回到顶部
帅哥哟,离线,有人找我吗?
migold
  2楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/8/7 9:38:00 [只看该作者]

我前一阵子,是狐老大,教我用TXT的读取方式,或者调用存储过程


 回到顶部
帅哥哟,离线,有人找我吗?
migold
  3楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/8/7 9:40:00 [只看该作者]

我上次就在想,如果不使用TXT的读取方式,或者调用存储过程,还有什么方式呢?
终于试出以上的方式,可以代替。就是不知道???

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2009/8/7 9:44:00 [只看该作者]

最开始加一行:
Dim ln AS Srring = Chr(13) & Chr(10)

然后将后面的Chr(13) & Chr(10)用ln代替

 回到顶部
帅哥哟,离线,有人找我吗?
migold
  5楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/8/7 10:12:00 [只看该作者]

Dim ln AS String = Chr(13) & Chr(10)
Dim Sum3 As string = "select Prod_ID," & ln
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -isnull(Prod_Number,0) else isnull(Prod_Number,0) end) AS 'Prod_Number'," & ln
Sum3 = Sum3 + "sum(case when d.billtype2=16 then 0 else isnull(DisMoney,0) end) AS 'DisMoney1'," & ln
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -isnull(DisMoney,0) else 0 end) AS 'DisMoney2'," & ln
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -isnull(DisMoney,0) else isnull(DisMoney,0) end) AS 'DisMoney'," & ln
Sum3 = Sum3 + "sum(case when d.billtype2=16 then 0 else isnull(CostMoney,0) end) AS 'CostMoney1'," & ln
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -isnull(CostMoney,0) else 0 end) AS 'CostMoney2'," & ln
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -isnull(CostMoney,0) else isnull(CostMoney,0) end) AS 'CostMoney'," & ln
Sum3 = Sum3 + "sum(case when d.billtype2=16 then -(isnull(dismoney,0)-isnull(costmoney,0)) else (isnull(dismoney,0)-isnull(costmoney,0)) end) ProfitMoney," & ln
Sum3 = Sum3 + "'零售'AS 'type','最近1个月' AS 'month'" & ln
Sum3 = Sum3 + "from ListSale A" & ln
Sum3 = Sum3 + "left join (select autoid,unit_id,billtype,billdate,s_Syb from masterbill) b on a.bill_id=b.autoid" & ln
Sum3 = Sum3 + "left join (select s_id from units) c on b.unit_id=c.s_id" & ln
Sum3 = Sum3 + "left join (select billtype billtype2,billname from billtype) d on b.billtype=d.billtype2" & ln
Sum3 = Sum3 + "left join (select s_id,u_Code,u_Name from product) e on a.prod_id=e.s_id" & ln
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))" & ln
Sum3 = Sum3 + "And e.u_Code in ('240325','240461','244610','243095','246364','248180','248599','013430','012947','115398')" & ln
Sum3 = Sum3 + "GROUP BY Prod_ID" & ln
Output.Show(Sum3)

是这样?

 回到顶部
美女呀,离线,留言给我吧!
yangming
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:超级版主 帖子:4109 积分:23338 威望:0 精华:21 注册:2008/9/1 20:07:00
  发帖心情 Post By:2009/8/7 11:09:00 [只看该作者]

以下是引用狐狸爸爸在2009-8-7 9:44:00的发言:
最开始加一行:
Dim ln AS Srring = Chr(13) & Chr(10)

然后将后面的Chr(13) & Chr(10)用ln代替

又学了一招,我怎么就想不到呢,呵呵


 回到顶部