Character columns of SQL Max

Source: Internet
Author: User

SQL Max can be used to calculate numeric or character columns.

 

However, you must pay attention to the special case of Max character columns.

For example, if the key column is a character column, there are currently 1, 2, 3, 4, 5... 9 Data

Now add 1 to the front to get the next key value.

 

The general method is as follows:

Declare @ next_key int
Select @ next_key = max (customsort) from persons

Print @ next_key + 1

 

The above code always returns 10, resulting in no auto-increment of next_key.

 

Declare @ next_key int

Select @ next_key = max (cast (customsort as INT) from persons

Print @ next_key + 1

 

The preceding method converts customsort to int to automatically increase the key.

Related Article

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.