joe_pool_is Posted January 17, 2008 Posted January 17, 2008 We need to display the Employee name as a single "LastName, FirstName" column in our DataGrid. In the Employee table, these columns are separate:SELECT LastName, FirstName FROM dbo.EmployeeIs there a way to format an SQL command so that these two columns get merged? I'm looking for something like this:SELECT (LastName, ", " FirstName) AS "EmployeeName" FROM dbo.EmployeeOf course, that doesn't work! Quote Avoid Sears Home Improvement
Administrators PlausiblyDamp Posted January 18, 2008 Administrators Posted January 18, 2008 [Highlight=sql] SELECT LastName + ', ' + FirstName as 'Employeename' FROM dbo.Employee [/highlight] should do the trick with SQL Server Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joe_pool_is Posted January 18, 2008 Author Posted January 18, 2008 Wow! I got a reply from the Master! :) I ran the code your way on the SQL Server through the Enterprise Manager GUI, and it worked fine. However, whenever I tried using it in VS, I got the message "Incorrect syntax near the keyword 'AS'." Is there any reason why SQL Server can run this but VS can't? Quote Avoid Sears Home Improvement
joe_pool_is Posted January 18, 2008 Author Posted January 18, 2008 Whoops! Syntax issues. I forgot to include the "+" before FirstName. Thanks Plausibly! Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.