Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
What's New in SQL Server 2012

You're reading from  What's New in SQL Server 2012

Product type Book
Published in Oct 2012
Publisher Packt
ISBN-13 9781849687348
Pages 238 pages
Edition 1st Edition
Languages

Table of Contents (19) Chapters

What's New in SQL Server 2012
Credits
About the Authors
Acknowledgment
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
1. Installing SQL Server 2012 2. SQL Server Administration 3. Transact SQL 4. Analysis Services 5. Reporting Services 6. Integration Services 7. Data Quality Services 8. AlwaysOn 9. Distributed Replay 10. Big Data and the Cloud Index

WITH RESULT SETS


The EXECUTE statement has been extended in SQL Server 2012 to include the WITH RESULT SETS option. This allows you to change the column names and data types of the result set returned in the execution of a stored procedure.

We will jump straight into an example to see how this works. The following procedure returns a straightforward result set using the Employee table we created in the previous section:

CREATE PROC spGet_Employees
AS
SELECT EmployeeID, FirstName, LastName
FROM Employee
ORDER BY EmployeeID

If we call this stored procedure in the usual way it will return all columns. The data type of each column will be the same as the column type in the table.

EXEC spGet_Employees

In the previous section, we used the mySequence SEQUENCE object to set the value that was inserted into the EmployeeID column. We want to return the result set so the integer EmployeeID column is a varchar instead. To see how you can easily change the name of the columns, we will output EmployeeID as...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}