Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need help with a complicated select query

Author  Topic 

dsylebee
Starting Member

8 Posts

Posted - 2009-11-29 : 14:35:45
Hi everyone id like to know how i can do this.

Im binding my table to an object in sql server.

so let's say i have 3 fields ( making it easier :o )

I have

id
firstname
lastname

what i want is to get 4 fields with my select

SELECT id, firstname, lastname, (firstname + space) As fullname + lastname FROM contacts ORDER BY lastname

i don't know how to merge those 2 fields thanks in advance. :)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-29 : 14:40:21
Not complicated, but this should be done in the presentation layer instead. You should only return firstname and lastname as separate columns and then concatenate them for display in your application.

SELECT id, firstname, lastname, firstname + lastname AS fullname
FROM contacts
ORDER BY lastname

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

dsylebee
Starting Member

8 Posts

Posted - 2009-11-29 : 14:42:39
"SELECT *, (c_lastname + ' ' + c_firstname) As c_fullname FROM contacts ORDER BY c_lastname"

thanks anyways :)
Go to Top of Page

dsylebee
Starting Member

8 Posts

Posted - 2009-11-29 : 14:45:12
quote:
Originally posted by tkizer

Not complicated, but this should be done in the presentation layer instead. You should only return firstname and lastname as separate columns and then concatenate them for display in your application.

SELECT id, firstname, lastname, firstname + lastname AS fullname
FROM contacts
ORDER BY lastname

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."



I would but the listbox from C# only accepts binding context of one field from a dataset so it's way more simple to create a temp field in a record set since i'm using non-queries to store and update my database thanks for your tip.
Go to Top of Page
   

- Advertisement -