我正在制作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.
是否有另一种方法可以为数据集编写类似%的查询?
请帮帮我。
答案 0 :(得分: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;
答案 1 :(得分:1)
如果对文字字符使用连接,它将起作用:
where Party_Code=@pcode and Sauda_Date like @saudaDate+'%' and Scrip_Code=@scripCode