[英]Where clause in windows phone using sql server compact tool 3.5
[英]Using CTE on SQL Server Compact 3.5
這是我關於stackoverflow的第一篇文章,我希望其中很多!
我的問題是:我在查詢中使用CTE來檢測和刪除表中的重復記錄。 此查詢在SQL Server 2005/2008中工作正常,但在Compact中它會引發異常:
解析查詢時出錯。 [令牌行號= 1,令牌行偏移量= 1,令牌錯誤= WITH]
這是我的查詢:
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();
我是否缺少某些東西,或者CTE在SQL Server Compact上不起作用?
移動版本CTE不支持某些功能,例如,存儲過程在移動版本上不起作用。 您可以使用免費的快速版本
您可能只是嵌套查詢,像這樣(可能有一些語法問題):
DELETE FROM Accounts
WHERE accountid IN (
SELECT Accounts.accountid
FROM Accounts
INNER JOIN (
SELECT UserName,min(accountid) accountid
FROM Accounts
GROUP BY username
HAVING Count(*) > 1
) Dublicates_CTE
ON Accounts.Username = Dublicates_CTE.Username
AND Accounts.accountid <> Dublicates_CTE.accountid
)
為了將來,這是一個很好的鏈接SQL Server Compact和SQL Server之間的差異
關於SQL Compact 3.5的TSQL子集是否可以使用公用表表達式的一些證明:
使用Visual Studio 2010和新的SQL Compact .sdf文件進行了測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.