asp.net - Wrong query: Incorrect syntax near ')' -


i have asp.net application , use dapper library. code produces error looks following:

public bool checkifexists(ienumerable<long> ticketgroups, long dateid, int userid) {     bool bretval = false;     string sql = "if exists (select * t_ticketgroupstochangeprice subtypeid = @subtypeid , dateid = @dateid , userid = @userid)";     using (var conn = createsqlconnection())     try     {         int rows = conn.execute(sql, ticketgroups.select(g => new { subtypeid = g, userid = userid, dateid }));         if (rows > 0)             bretval = true;     }     catch (sqlexception ex)     {         throw new exception("error", ex);     }      return bretval; } 

when run application throws exeption: incorrect syntax near ')'

as can see, there can more tickets (ienumerable type) same date , user.

i'm not sure what's going on.

that because not valid sql start if (if mean use t-sql is, have write entire if statement)

i think simple case need:

select case        when exists (select * t_ticketgroupstochangeprice subtypeid = @subtypeid , dateid = @dateid , userid = @userid)        1        else 0        end 

Comments