SQLServer 2008中SQL加強之一:Values新用處。本站提示廣大學習愛好者:(SQLServer 2008中SQL加強之一:Values新用處)文章只能為提供參考,不一定能成為您想要的結果。以下是SQLServer 2008中SQL加強之一:Values新用處正文
Create table Demo_Values
(PKID int not null identity(1,1) primary key
,DName Nvarchar(20) null
,DCode NVarchar(30) 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)
除可以一次性拔出多行,values還有更奇妙的用法,不應用永遠表或暫時表而表現一個成果集,並且不須要函數或表變量。看上面的例子:
--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
*/
留意該語句的最初一行界說了“源”稱號和列名,個中列名用於select語句。
自己來自 cnblogs 邀月
[email protected]