Some basics of new knowledge of SQL Server database

Source: Internet
Author: User

Recently to contact the SQL Server stored procedures, before dealing with more complex logic process, look at the basic syntax of these SQL, I feel a little bit more complicated SQL statement, suddenly found that I was weak ah, so in some basic grammar I would like to re-organize some of it, Let's meet a few points below.

I. how SQL Server understands: The difference between IsNull (a,0) and IsNull (a,0) <>0 and the use of SELECT INTO

            Select2fromwhere isnull (ID,0) =0and  id like'  a%'

<1> First of all, let's say the into bar used in the SELECT statement here, where we often encounter the Select table field from the table name, but here we add an into to the from front In fact, this is the query out of the table field and content added to a new table;

<2> again, the preceding isnull (parameter 1, parameter 2) determines whether the parameter 1 is NULL, or returns the parameter 1 if the parameter 2 is returned, and the situation here is: IsNull (column name, 0): IsNull () The function is used to determine whether the column name is null if NULL returns 0 otherwise the value of the column name; <>: Is not equal to! = Same As for example: Select 3 where 1<>2 the result is 3 select 3 where 1<>1 the result is not found; isnull (column name, 0) <>0: First determine if the column name is null and then compare with 0 equals zero Returns the result to true otherwise false.

two. Case-when usage in SQL Server

            set a.id= case b.bid                                1                                        else 2                                         End                                 from  STUDENT a                                 join #C C                                = c.cid

See this here to know, in fact, is to judge, sub-situation. Before I did not touch a lot of this, see the time did not understand what to do, but I know that case is a method, hey. This is the magic of SQL Server.

three. Mixed use of INSERT statements and SELECT statements

            Select ID,'abc' as varchar ( from STUDENT;

Here is the information that is inserted in the existing register table, but we know from the INSERT statement that it seems that the insertion information time needs to be added to the values (), but here we can omit, As long as we add all the fields in the Register table, here the "ABC" can be the information of the returned field of a stored procedure, or it can be a method of a call to query out the information;

Another thing to say about the use of cast is that casting is actually an expression that converts an expression of a data type to another data type.

Temporarily first write here, hey, to lunch break, the next will try to organize the SQL syntax and some knowledge of the stored procedures, before the method is too weak in this way, refueling, hey.

Some basics of new knowledge of SQL Server database

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.