サッカー チームがプレーした直近 6 試合をテーブルに入力する次の MySQL コマンドがあります。
insert into lastxgames
select team, matchdate, hometeam, awayteam, fthg, ftag
from (
select
team, soccerdata.matchdate, hometeam, awayteam, fthg, ftag,
@teamCounter:=IF(@prevHome=team,@teamCounter+1,1) teamCounter,
@prevHome:=team
from soccerdata
join (
select distinct matchdate, hometeam team
from soccerdata
union
select distinct matchdate, awayteam
from soccerdata
) allgames on soccerdata.matchdate = allgames.matchdate
and (soccerdata.hometeam = allgames.team or soccerdata.awayteam = allgames.team)
join (select @teamCounter:=0) t
order by team, soccerdata.matchdate desc
) t
where teamCounter <= 6
order by team, matchdate desc;
これを C# プログラム内から実行したいのですが、MySQL が意図した方法 (MySQL 変数?) で処理されるのではなく、@ 記号がクエリ パラメータとして使用されるため、クエリが失敗します。
私の C# プログラム内では、クエリを保持する文字列を宣言し、それを MySqlCommand に追加しています。
string insertCommand = @"insert into lastxgames...";
using (MySqlCommand cmdInsert = new MySqlCommand(insertCommand, dcConnection))
{
cmdInsert.ExecuteNonQuery();
}
@teamCounter と @prevHome がクエリ パラメータとして扱われないように、C# で @ 記号を無視する方法はありますか?