Null small problem in SQL, Big bug

Source: Internet
Author: User

Today in writing a refund of the SQL encountered a problem, directly resulting in the previous record of all operations log, emptied, fortunately, I have to look at the data habits, the following code

1UPDATEtradeuser2 SET 3 Userscore=@UserScore 4 Remark=ISNULL (Remark,')+  ' +@UserName +' manually cancel payment, return points '5 WHERE UserId=@UserID  

After the execution of this SQL, the comments are emptied directly, the solution can not find the reason. In fact, the reason is very simple, the incoming @username is null, resulting in a string and null evaluates to NULL, this knowledge point is actually known, but the use of the time is ignored, can be changed to the following

    UPDATETradeuserSETUserscore=@UserScoreRemark=ISNULL(Remark,"')+' '+ISNULL(@UserName,"')+'Cancel payment manually and refund points'--This is a custom problem of writing code, with IsNull () judging the incoming parameters .     WHEREUserid=@UserID

This kind of problem can be avoided, this is a programmer thinking logic is rigorous, work attitude is correct, oneself to develop the things responsible for themselves. Have doubts to ask more, or out of the problem more embarrassing

02 Development is more validation conditions, as far as possible to avoid empty field values to appear, to minimize the execution of code, do not need to implement the situation should be avoided.

The article speaks the technical point is not many, most are the cumbersome narration, the BO main expression ability is not very strong, cannot concise narrative question, please understanding.

Null small problem in SQL, Big bug

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.