using the Select "AS" statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to combine two fields in the SELECT statement?
I'm forced to do this there because in ASP.NET the population of a dropdown
field only allows the one field to be inserted as the "Value" of the list.
I was thinking that if I could do this in the SELECT statement that would
slove my issue.
i.e.
"SELECT (FNAME & " " & LNAME AS full name) FROM NAMES"
something like this.
thanx.
 
Hi Chris,

Depends on the database used.
If you are dealing with sql server, it would be something like:
SELECT FNAME + ' ' + LNAME AS [full name] FROM NAMES

Note that I don't recommened spaces in metadata - FullName would be better.
 
thanx! thanx! thanx! that did the trick!

Miha Markic said:
Hi Chris,

Depends on the database used.
If you are dealing with sql server, it would be something like:
SELECT FNAME + ' ' + LNAME AS [full name] FROM NAMES

Note that I don't recommened spaces in metadata - FullName would be better.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Chris said:
Is there a way to combine two fields in the SELECT statement?
I'm forced to do this there because in ASP.NET the population of a
dropdown
field only allows the one field to be inserted as the "Value" of the list.
I was thinking that if I could do this in the SELECT statement that would
slove my issue.
i.e.
"SELECT (FNAME & " " & LNAME AS full name) FROM NAMES"
something like this.
thanx.
 
Hi Chris,

You would be better of solving this issue by adding an expression column to
your DataTable that contains the combination of the first and last name. You
can then bind the ComboBox to the DataTable and specify the expression
column as the DisplayMember.
 
Hi Diego,

Why do you think this is a better solution?
You have to retrieve the same data amount + there is expression column
overhead.
 
What will you do when in the future the application has to enable updating
the fields in the Names table? When you simply fill the DataTable with the
FName and LName field, and expand that table with an expression column that
contains the combination of the two previous fields, you can easily add
update functionality later by binding to the FName and LName fields.


Miha Markic said:
Hi Diego,

Why do you think this is a better solution?
You have to retrieve the same data amount + there is expression column
overhead.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Diego Deberdt said:
Hi Chris,

You would be better of solving this issue by adding an expression column
to
your DataTable that contains the combination of the first and last name.
You
can then bind the ComboBox to the DataTable and specify the expression
column as the DisplayMember.
 
Diego Deberdt said:
What will you do when in the future the application has to enable updating
the fields in the Names table? When you simply fill the DataTable with the
FName and LName field, and expand that table with an expression column
that
contains the combination of the two previous fields, you can easily add
update functionality later by binding to the FName and LName fields.

That's a different story then. Of course, if you need updating you have to
complicate it :-)
I would still avoid using expression columns though - I would rather fill
the concatenated column by code.
 
Back
Top