Hi Everyone,
This is my first post on stackoverflow, I hope one of many!
My question is this: I'm using CTE in a query to detect and remove duplicate records in a table. This query works just fine in SQL Server 2005 / 2008, but in Compact it throws an exception:
There was an error parsing the query. [ Token line number = 1,Token line offset = 1,Token in error = WITH ]
This is my query:
SqlCeConnection con = new SqlCeConnection(ConfigurationManager.ConnectionStrings["ADSLConnectionString"].ConnectionString);
SqlCeCommand command = new SqlCeCommand();
command.Connection = con;
command.CommandType = CommandType.Text;
command.CommandText = "WITH Dublicates_CTE(Username, accountid)" +
" AS" +
" (" +
" SELECT UserName,min(accountid)" +
" FROM Accounts" +
" GROUP BY username" +
" HAVING Count(*) > 1" +
" )" +
" DELETE FROM Accounts" +
" WHERE accountid IN (" +
" SELECT Accounts.accountid" +
" FROM Accounts" +
" INNER JOIN Dublicates_CTE" +
" ON Accounts.Username = Dublicates_CTE.Username" +
" AND Accounts.accountid <> Dublicates_CTE.accountid" +
" ) ";
con.Open();
command.ExecuteNonQuery();
Am I missing something, or does CTE not work on SQL Server Compact?