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
 General SQL Server Forums
 New to SQL Server Programming
 Combining two fields together

Author  Topic 

huynhtl
Posting Yak Master

107 Posts

Posted - 2008-04-03 : 10:45:09
Hi,
I was wondering if there's a way to combine last, first and middle name together in one field instead of three different ones?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-03 : 10:48:45
You want to combine them in query?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

huynhtl
Posting Yak Master

107 Posts

Posted - 2008-04-03 : 10:49:23
Yes, Please
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-03 : 10:50:01
SELECT ISNULL(lastname,'') + ISNULL(firstname,'') + ISNULL(middlename,'') AS FullName from YourTable

EDIT:Added ISNULL check to deal with NULL values in fields
Go to Top of Page

huynhtl
Posting Yak Master

107 Posts

Posted - 2008-04-03 : 11:06:17
Thanks. Is there a way to not have such major space between the last name and the first name? i.e, Doe ,John S
I want Doe, John S
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-03 : 11:08:03
Didnt get wat you are asking. Can you explain?
Go to Top of Page

huynhtl
Posting Yak Master

107 Posts

Posted - 2008-04-03 : 11:13:27
I've figure it out. Thanks.
Another problem, I want to combine my provider number and the provider name as one, but the error came back as
Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value 'CENTRAL WASHINGTON COMPREHENSIV' to a column of data type int.
Provider number is int and provider name is char(31). Is there a way to combine these two fields like the other one?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-03 : 11:19:04
yup. SELECT Providername + CAST(Providernumber as varchar(10))
Go to Top of Page

huynhtl
Posting Yak Master

107 Posts

Posted - 2008-04-03 : 11:32:02
Perfect!!!!!!!!!!!!!
Thank you so much. This makes my life easier.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-04 : 02:10:39
quote:
Originally posted by visakh16

Didnt get wat you are asking. Can you explain?


OP wants to trim firstname

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -