MSSQL Query method

Source: Internet
Author: User
Tags logical operators mssql

1. Simple query

1.1 Querying all columns

Example:select * from T_userinfo

1.2 Query Development columns

Example:select * from Username,password to T_userinfo

1.3 Querying for columns with calculations

Example:select age*15 from T_userinfo


2. Conditional query

1. Comparison operators

>, >=, =, <=, <, <>,!>,!< size comparison

Select age from T_userinfo where age<=30 and age>0

2. Range operator

SELECT * from T_userinfo where age between 1 and 30

3. List operators

SELECT * from T_userinfo where type in (' Premium Member ', ' Platinum Member ')//Query membership level is premium and platinum SELECT * from T_userinfo where type not in (' ordinary member ')// Query is not a regular member

4. Logical operators

SELECT * from T_userinfo where age>20 and type= ' Advanced members ' select * from T_userinfo where age>20 and type in (' Premium member ')

5. Null value operator

SELECT * FROM T_userinfo where username are nullselect * from T_userinfo where username are not null

6. Pattern operators

% matches any type and length of characters. For example a%, which represents a string of any length beginning with a

_ matches any single character. For example, A_b, a string with a length of 3 that begins with a and ends with B

[] User-specified range, for example [A-h], representing any single character within the A~h range

[^] User-specified range, for example [^a~h], representing any single character outside of the A~h range

SELECT * FROM T_userinfo where username like '% yuan% ' select * from T_userinfo where username like ' a____ '//query with a letter beginning with a length of 5. such as admin


MSSQL Query method

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.