mardi 27 janvier 2015

Concatenate Columns using ASP, VB, and SQL

I want to select two columns (first and last name) from a database, combine them into one, and stick them into a data set to be displayed in a datagrid. I also need to add a space between them for formatting.


My normal SQL statement:



SELECT first_name + ' ' + last_name as userName from Table


My current VB statement:



strSQL = "SELECT first_name + ' ' + last_name as userName from Table"


When I attempt to do this, my application throws the following error: System.Data.SqlClient.SqlException: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name.


EDIT: For those asking about the database and/or if this is the correct query, if I format my VB query as follows:



strSQL = "SELECT first_name + last_name as userName from Table"


I get the proper results, but then the column looks like FirstLast and is very difficult to read.


I'm guessing there's something small I'm missing on how to do this properly within VB. Can anyone advise?


Aucun commentaire:

Enregistrer un commentaire