J.Doe
J.Doe

Reputation: 139

Add names to a column that doesn't have a name already in SQL Server

I created a a stored procedure that returns a table that looks like this:

(No column name)  (No column name)
 2                4

The table has no name, but I'll call the procedure, "proc".

How would I change the name of the two columns that currently have no name, so basically:

ColA    AnotherColumn
---------------------
  2          4

Upvotes: 1

Views: 774

Answers (1)

S3S
S3S

Reputation: 25112

You need to alias them. This happens in a few cases, but often with aggregate functions and sub-queries

select
   sum(someColumn) as NewColumnName
   ,(select top 1 something From somewhere) ThisColumn  --notice the AS is optional
from YourTable

Another method which isn't ANSI standard is using =

select
   NewColumnName = sum(someColumn)
  ,ThisColumn = (select top 1 something From somewhere)
from YourTable

Upvotes: 3

Related Questions