[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 152
  • Last Modified:

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],
0
pstre
Asked:
pstre
1 Solution
 
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
 
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now