.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

What is the use of Row Constructor in Sql Server 2008?

Posted By: Deco     Posted Date: September 11, 2010    Points:2   Category :Sql Server
Can any one tell me the use of Row Constructor in Sql Server 2008?

Will be happy if you post with sample codings...

Responses
Author: Naim Khan             
Posted Date: September 13, 2010     Points: 5   

While playing with SQL Server 2008 I found new feature of "Row Constructors", where I can load temp table from stored procedure directly.

hello friend,

Look at the following SQL where I have to use OpenQuery from server to itself creating loopback server and execute stored procedure and insert into temp table.

INSERT INTO #TempTable
SELECT *
FROM OPENQUERY(ServerName, 'exec StoredProc')

Above mentioned same query can be now written with simpler statement as described here.

INSERT INTO #TempTable
EXEC StoredProc

Note that this does not work with real tables or any other objects. This feature is only available to load temp tables.

Naim Khan


Software Developer
khan.naim786@yahoo.com
khan.naeem1987@gmail.com
Author: Rajshree             
Posted Date: September 17, 2010     Points: 5   

Don't you feel boring sometimes when you have to write an script to insert multiple rows in a table and you do not have any other choice except writing multiple insert statements? In one of my previous posts I showed a way to insert multiple rows by using UNION ALL but wait! there is another way available in SQL Server 2008 called Row Constructor which is an ANSI terminology for pseudo table of rows.
It is actually a way to provide a set of row values in one statement. Following example will help you understand better. Please note that this example can work only on SQL Server 2008 or above:

-Switch to tempdb
Use tempdb
Go

-Create a test table in temdb
Create table tblCountries (id int, country varchar(50)
Go

-Inserting multiple values
Insert into tblCountries (id,country)
Values
(1,'USA'), -Row 1
(2,'UK'), -Row 2
(3,'France') -Row 3

-Now select, you will get 3 rows
Select * from tblCountries



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend