SQL statement help...

I am trying to rename the fields and cannot do it .. If I want to rename the following to Department Description, what syntax would I use.  I tried T1.[Segment1 Description] AS Department Description but got an error message.

T1.[Segment1 Description],
pstreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
If this is in a SELECT statement, you need to enclose the Alias in either square brackets ( [ ] ) or quotation marks ( " ). The alias cannot contain a space, special characters or reserved words without using them. EX:

AS [Department Description]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Randy PooleCommented:
Are you trying to return a different name from a select statement or rename the column in the database?
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Shaun Kline's answer is correct.   T1.[Segment1 Description] AS [Department Description]

I'll add my .02 in that the only time I would intentionally alias a column with a space is if the object I'm writing is used as the data source for a report, where you want the column headers to be English-user-readable.   Even then I'd consider stating the English-user-readable column header in the report, and not in the SQL code.

Otherwise, the forcing of square brackets [ ] is one more thing to potentially forget and cause an error.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
pstre - If you don't mind I'm going to unaccept the answer to allow for a regrade, specifically for a split between myself and Shaun Kline, as EE etiquette doesn't encourage an 'That guy's answer is correct' type comment to receive all points.

Thanks in advance.
Jim
0
pstreAuthor Commented:
Thank you... I was using spaces in the renaming of the column and that was the problem...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.