0

我正在制作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-% 查询?

请帮我。

4

2 回答 2

2

它应该是

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;
于 2013-03-15T10:23:33.093 回答
1

如果您对文字字符使用串联,它将起作用:

where Party_Code=@pcode and Sauda_Date like @saudaDate+'%' and Scrip_Code=@scripCode
于 2013-03-15T10:26:21.443 回答