【问题标题】:Error in DataSet数据集中错误
【发布时间】:2013-03-15 10:19:08
【问题描述】:

我正在制作Windows Application,因为我正在创建用于制作报告的数据集,因为我正在使用一个已经成功运行的查询来显示网格中的数据。但它不适用于数据集。

查询

select sum (case when Buy_sell=1 then Trade_Qty else 0 end) as BuyQty,
       sum (case when Buy_sell=1 then Market_Rate else 0 end) as BuyRate,
       sum (case when Buy_sell=1 then Trade_Qty*Market_Rate else 0 end) as BuyAmount,

       sum (case when Buy_sell=2 then Trade_Qty else 0 end) as SellQty,
       sum (case when Buy_sell=2 then Market_Rate else 0 end) as SellRate,
       sum (case when Buy_sell=2 then Trade_Qty*Market_Rate else 0 end) as SellAmount
from tradeFile
where Party_Code=@pcode and Sauda_Date like @saudaDate% and Scrip_Code=@scripCode

它给我在 Sauda_Date 附近的 % 错误,如 @saudaDate%。如果我删除 % 它不会给出错误,但它没有给我预期的结果。

查询文字

Error in WHERE clause near 'AND'.
Unable to parse query text.

还有其他方法可以为数据集编写 like-% 查询吗?

请帮帮我。

【问题讨论】:

  • 你正面临字符串连接的问题...
  • Sauda_Date的类型是什么?
  • @trailmax :成功了。谢谢
  • @trailmax :将其发布为答案。
  • @HenkHolterman 不,我得到了解决方案。 +'%' 有问题。

标签: c# .net database sql-server-2005 dataset


【解决方案1】:

应该是

string query="select sum (case when Buy_sell=1 then Trade_Qty else 0 end) as BuyQty,
       sum (case when Buy_sell=1 then Market_Rate else 0 end) as BuyRate,
       sum (case when Buy_sell=1 then Trade_Qty*Market_Rate else 0 end) as BuyAmount,

       sum (case when Buy_sell=2 then Trade_Qty else 0 end) as SellQty,
       sum (case when Buy_sell=2 then Market_Rate else 0 end) as SellRate,
       sum (case when Buy_sell=2 then Trade_Qty*Market_Rate else 0 end) as SellAmount
from tradeFile
where Party_Code="+@pcode+" and Sauda_Date like "+ @saudaDate+"%"+" and Scrip_Code="+@scripCode;

【讨论】:

    【解决方案2】:

    如果你对文字字符使用串联,它会起作用:

    where Party_Code=@pcode and Sauda_Date like @saudaDate+'%' and Scrip_Code=@scripCode
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-16
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      • 2022-08-26
      • 2018-12-05
      • 2011-03-09
      相关资源
      最近更新 更多