开发者

How do i use the top keyword in an insert statement?

I was using it as LIMIT when I got the exception Incorrect syntax near the keyword 'TOP'.

Maybe I 开发者_StackOverflow社区can omit it in this case without a problem, but if I couldn't where do I put top?

INSERT INTO [user_data] (...) SELECT 
...
@14 WHERE not exists (SELECT * FROM [user_data] WHERE [email] = @15 OR 
[name] = @16 OR 
[unconfirmed_email] = @17 TOP 1);


TOP goes after SELECT in SQL Server, not like where LIMIT goes in other DBMSes.

SELECT TOP 1 <fields> FROM ...

So your query would become:

INSERT INTO [user_data] (...) SELECT
...
@14 WHERE not exists (SELECT TOP 1 * FROM [user_data] WHERE [email] = @15 OR 
[name] = @16 OR 
[unconfirmed_email] = @17);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜