Drop Table
Support Forum for database administrators and web based access to important newsgroups related to databasesHi, 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
Post Follow-up to this messageSQL 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.
Post Follow-up to this messageSELECT LastName + ", " + FirstName AS Name FROM EmployeeTBL ORDER BY Name This should work.
Post Follow-up to this messageUse single qutes instead of double: SELECT LastName + ', ' + FirstName AS Name FROM EmployeeTBL ORDER BY LastName
Post Follow-up to this messageHmm, 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.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread