Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Grouping columns
Hi,

I was trying to retrieve some data in such a way that it 2 columns will
be merged into one, with a column in between.  I am trying to do
something like this:

SELECT     LastName + ", " + FirstName AS Name
FROM         EmployeeTBL
ORDER BY LastName

But SQL Server does not like this syntax (though it does work with
"LastName + FirstName").

I appreciate any help.

Thanks,
Aaron


Report this thread to moderator Post Follow-up to this message
Old Post
hartley_aaron@hotmail.com
03-31-05 12:04 AM


Re: Grouping columns
SQL Server uses single quotes for strings, not double quotes. Also...
you probably want to order by the first name if the last name is the
same, correct? Try:

SELECT LastName + ', ' + FirstName AS Name
FROM EmployeeTBL
ORDER BY LastName, FirstName

If it is possible for there to be NULL values or empty strings in
either of the columns then you will need to account for that as well.

HTH,
-Tom.


Report this thread to moderator Post Follow-up to this message
Old Post
Thomas R. Hummel
03-31-05 12:04 AM


Re: Grouping columns
SELECT     LastName + ", " + FirstName AS Name
FROM         EmployeeTBL
ORDER BY Name

This should work.


Report this thread to moderator Post Follow-up to this message
Old Post
SQL_developer
03-31-05 12:04 AM


Re: Grouping columns
Use single qutes instead of double:

SELECT     LastName + ', ' + FirstName AS Name
FROM         EmployeeTBL
ORDER BY LastName


Report this thread to moderator Post Follow-up to this message
Old Post
boblotz2001@yahoo.com
03-31-05 12:04 AM


Re: Grouping columns
Hmm, I didn't notice the double quotes ealier.

SELECT     LastName + ', ' + FirstName AS Name
FROM         EmployeeTBL
ORDER BY Name

You can always use the final column name in the ORDER BY condition.


Report this thread to moderator Post Follow-up to this message
Old Post
SQL_developer
04-01-05 01:03 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 01:25 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006