SQL Drip 29-errors everywhere

Source: Internet
Author: User

Original: SQL Drip 29-error everywhere

I just want to say that the following are very basic SQL knowledge, but it is easy to make mistakes. So open our eyes, hold our breath, check it carefully!

Case 1
If not EXISTS (select OrderID from Corpemailsendqueue where orderid=600643425)
Begin
EXEC sp3_corpemailsendqueue_i @ID =null, @OrderID =600643425, @OrderType = ' F ', @EmailType = '-2 ', @ResendTime =0, @SendTime =null, @CurrentStatus = ' u ', @GenerateTime =null
End

This is the final correct wording, it seems simple, but in some places it is easy to make mistakes.



Error 1

If not EXISTS select COUNT (1) from Corpemailsendqueue where orderid=600643425
Begin
EXEC sp3_corpemailsendqueue_i @ID =null, @OrderID =600643425, @OrderType = ' F ', @EmailType = '-2 ', @ResendTime =0, @SendTime =null, @CurrentStatus = ' u ', @GenerateTime =null
End

It seems to be OK, but it will be an error, the following errors:

MSG 156, Level A, State 1, line 1
Incorrect syntax near the keyword ' select '. You need to wrap the select COUNT (1) from Corpemailsendqueue where orderid=600643425 with the brackets.



Error 2

If not EXISTS (select COUNT (1) from Corpemailsendqueue where orderid=600643425)
Begin
EXEC sp3_corpemailsendqueue_i @ID =null, @OrderID =600643425, @OrderType = ' F ', @EmailType = '-2 ', @ResendTime =0, @SendTime =null, @CurrentStatus = ' u ', @GenerateTime =null
End

It doesn't seem to be a problem, but after replacing OrderID with Count (1), exists doesn't work, select COUNT (1) from Corpemailsendqueue where orderid=600643425 In any case there is value, I mean even 0 is exists, so the following stored procedure is not executed under any circumstances.

Case 2

Select DateDiff (hh, ' 2013-11-21 16:50 ', ' 2013-11-21 17:35 ') This gets the result is actually 1, I think SQL Server is not the convulsions, the two time difference between 45 minutes, less than 1 hours, Helpless can only use Select DateDiff (MI, ' 2013-11-21 16:50 ', ' 2013-11-21 17:35 ') to get the result is 45.

There is also a little knowledge, if you want to get the current time can be used getdate (), if it is UTC time, is the current time minus 8, you can use getUTCDate ().

SQL Drip 29-errors everywhere

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.