MYSQL SELECT into record empty issue

Source: Internet
Author: User


SELECT Id into @Id from giftcode WHERE Status = 1 and Giftid = #GiftId # ORDER by Id ASC LIMIT 1;
UPDATE giftcode SET usedtime = Now (), Status = 2,accountid = #AccountId # WHERE Id = @Id;
SELECT * from Giftcode WHERE Id = @Id;

Title, this 3 sentence SQL, there is no problem in server, if in MySQL, because the first sentence does not find records, affecting the number of rows is 0, does not perform into operations

The @Id variable that maintains the results from the previous session. (@ is a session variable), causing a program problem

Workaround:

In the first sentence: SET @Id = 0;

Can be solved, if there is a better solution, please post!

Environment: ASP. NET Framework 3.5/ibatis.net/mysql

MYSQL SELECT into record empty issue

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.