One of SQL enhancements in SQL Server 2008: Values new use _mssql2008

Source: Internet
Author: User
Tags dname getdate
Copy Code code as follows:

Create Table Demo_values
(pkid int NOT null identity (1,1) primary key
, dname Nvarchar () null
, Dcode NVarchar () null
, ddate datetime NULL
)
Go

--this SQL is only for SQL Server 2008
Insert into Demo_values
(dname,dcode,ddate)
Values
(' Demoa ', ' AAA ', GETDATE ()),
(' demob ', ' BBB ', GETDATE ()),
(' Democ ', ' CCC ', GETDATE ()),
(' Demod ', ' DDD ', GETDATE ()),
(' DeMoe ', ' EEE ', GETDATE ())

--(5 row (s) affected)

In addition to being able to insert multiple rows at once, values also have a more ingenious use, representing a result set without using a permanent table or a temporary table, and no function or table variables are required. Look at the following example:
Copy Code code as follows:

--this SQL is only for SQL Server 2008
Select Dname,dcode,ddate
From
(Values
(' Demoa ', ' AAA ', GETDATE ()),
(' demob ', ' BBB ', GETDATE ()),
(' Democ ', ' CCC ', GETDATE ()),
(' Demod ', ' DDD ', GETDATE ()),
(' DeMoe ', ' EEE ', GETDATE ())
)
Demo_values (Dname,dcode,ddate)
--(5 row (s) affected)

/*
Dname Dcode Ddate
Demoa AAA 2010-10-12 20:37:45.500
Demob BBB 2010-10-12 20:37:45.500
Democ CCC 2010-10-12 20:37:45.500
Demod DDD 2010-10-12 20:37:45.500
DeMoe EEE 2010-10-12 20:37:45.500
*/

Note the last line of the statement defines the source name and column name, where the column name is used for the SELECT statement.

I come from Cnblogs invited month 3w@live.cn
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.