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.
Author |
Topic |
Tade
Starting Member
5 Posts |
Posted - 2010-10-18 : 09:10:02
|
Hey all.I wrote a small script to create a View that displays two tables from two different databases, using Inner Joins and Unions commands.The result columns were as follows:ID FirstName LastNameWhat I need to do now, is in that same View combine column 2 and 3 (FirstName and LastName) into a new column called FullName, and have the result display only the ID and FullName column, as follows:ID FullNameI need it all to be in one script as I'm going to save the View itself and use it later in a C# Project.Thanks in advance for the help! |
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-10-18 : 09:16:14
|
You can concatenate the two columns to get the computed column.Example isnull(Firstname + ' ','') + isnull(LastName , '') as FullName |
 |
|
Tade
Starting Member
5 Posts |
Posted - 2010-10-18 : 09:56:32
|
Thanks for the fast reply, but I'm not sure I got it.I don't understand where to insert that line. Perhaps if I wrote down the script you'd be able to help me a bit more? Here it is:SELECT DISTINCT Library.dbo.tblOutsiders.ID, Library.dbo.tblOutsiders.FirstName COLLATE Hebrew_CI_AS,Library.dbo.tblOutsiders.LastName COLLATE Hebrew_CI_ASFROM Library.dbo.tblOutsiders CROSS JOIN Org.dbo.tblPersonUNIONSELECT DISTINCT Org.dbo.tblPerson.ID, Org.dbo.tblPerson.FirstName COLLATE Hebrew_CI_AS, Org.dbo.tblPerson.LastName COLLATE Hebrew_CI_ASFROM Library.dbo.tblOutsiders CROSS JOIN Org.dbo.tblPerson When I execute that query, I get the results that I need to combine together into one column.Where do I write the command line you described?Again, thanks in advance. |
 |
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-10-18 : 13:31:30
|
Try this:SELECT DISTINCT L.ID, L.FirstName COLLATE Hebrew_CI_AS, L.LastName COLLATE Hebrew_CI_AS, Isnull(L.FirstName COLLATE Hebrew_CI_AS + ' ','') + Isnull(L.FirstName COLLATE Hebrew_CI_AS ,'') as FullNameFROM Library.dbo.tblOutsiders L CROSS JOIN Org.dbo.tblPerson PUNIONSELECT DISTINCT O.ID, O.FirstName COLLATE Hebrew_CI_AS, O.LastName COLLATE Hebrew_CI_AS, Isnull(O.FirstName COLLATE Hebrew_CI_AS + ' ','') + Isnull(O.FirstName COLLATE Hebrew_CI_AS ,'') as FullNameFROM Library.dbo.tblOutsiders O CROSS JOIN Org.dbo.tblPerson TRegards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
Tade
Starting Member
5 Posts |
Posted - 2010-10-19 : 04:56:47
|
That worked great. After reading up on everything you said I now understand what it does, too, instead of just copy & pasting.Thanks for the help! |
 |
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-10-19 : 06:27:13
|
quote: Originally posted by Tade That worked great. After reading up on everything you said I now understand what it does, too, instead of just copy & pasting.Thanks for the help!
Welcome |
 |
|
|
|
|
|
|