When you execute a stored procedure that returns a result set in SQL Server, the columns returned are defined in the stored procedure.
But did you know that you can redefine those columns?
What I mean is, you can change the names and/or the data type of the columns returned in the result set.
This could save you from having to fiddle with the column headers and data formats in the event you needed to use that result set in another setting.
For example, if a stored procedure returns a datetime2 column, but you only need the date part, you could specify date for that column, and your result set will only include the date part.
And the best part is that you can do it as part of the EXECUTE
statement. No need to massage the data after executing the procedure. way to do this is by using the WITH RESULT SETS
clause of the EXECUTE
statement.
Continue reading →