| Author |
Topic |
|
JPG
Starting Member
10 Posts |
Posted - 2011-12-23 : 01:03:05
|
| hello..how can i join the two columns from one table..?jpgervacio |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
JPG
Starting Member
10 Posts |
Posted - 2011-12-23 : 01:16:58
|
| This is my table..UserFirstName|UserLastNameAlex |RiveraAna |San Sebastianand the output that I want to show is something like this..UserNameAlex RiveraAna San Sebastianjpgervacio |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-23 : 01:19:41
|
its not joining but its called concatenationSELECT COALESCE(UserFirstName + ' ','') + COALESCE(UserLastName,'') AS UserNameFROM table Add the COALESCE only if columns are nullable------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
JPG
Starting Member
10 Posts |
Posted - 2011-12-23 : 01:26:55
|
| there's an error in my program after I put the syntax.. *Error converting data type nvarchar to numeric.jpgervacio |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
JPG
Starting Member
10 Posts |
Posted - 2011-12-23 : 01:33:53
|
| @visakh16sorry I didn't know that it is called concatenation, thank you for the correction :)jpgervacio |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-23 : 01:35:13
|
quote: Originally posted by JPG there's an error in my program after I put the syntax.. *Error converting data type nvarchar to numeric.jpgervacio
hmmhow come your username field is numeric? Didnt understand the reason for that. please use appropriate datatype for your columnsit should be varcharif not, you've to do explicit castingSELECT COALESCE(CAST(UserFirstName AS varchar(100))+ ' ','') + COALESCE(CAST(UserLastName AS varchar(100)),'') AS UserNameFROM table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
JPG
Starting Member
10 Posts |
Posted - 2011-12-23 : 01:36:46
|
| @tkizer I'm not using numeric I don't know why it is the error :|jpgervacio |
 |
|
|
JPG
Starting Member
10 Posts |
Posted - 2011-12-23 : 01:40:51
|
| Actually this is my sample prog.. SELECT RestaurantMaster.RestaurantCode, RestaurantMaster.RestaurantName, OrdersHistory.OrderNo, OrdersHistory.OrderSourceText AS OrderSource, OrdersHistory.PaymentTypeText AS PaymentType, SUM(OrdersHistory.NetTotal) AS NetPrice, SUM(OrdersHistory.GrossTotal) AS GrossPrice, ReasonMaster.ReasonDescription AS Reason, COALESCE(CAST(UserFirstName AS varchar(100))+ ' ','') + COALESCE(CAST(UserLastName AS varchar(100)),'') AS UserNameFROM OrdersHistory JOIN ReasonMaster ON OrdersHistory.ReasonFKID = ReasonMaster.PKID JOIN RestaurantMaster ON RestaurantMaster.PKID = OrdersHistory.RestaurantID JOIN UserMaster ON OrdersHistory.MessageUserId = UserMaster.UserID WHERE OrdersHistory.OrderDate BETWEEN '2011-11-01' AND '2011-12-01' AND OrdersHistory.StatusFKID = 3 GROUP BY RestaurantMaster.RestaurantCode, RestaurantMaster.RestaurantName, OrdersHistory.OrderNo, OrdersHistory.OrderSourceText, OrdersHistory.PaymentTypeText, ReasonMaster.ReasonDescription, UserMaster.UserFirstName, UserMaster.UserLastName;and I don't know why the error is..*Error converting data type nvarchar to numeric. :'(jpgervacio |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-23 : 01:52:55
|
| can you check data types for UserFirstName ,UserLastName ,NetTotal,GrossTotalI doubt whether error is caused by concatenation. it can even be from those SUM() above if NetTotal,GrossTotal etc are not numeric------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
JPG
Starting Member
10 Posts |
Posted - 2011-12-23 : 01:59:56
|
| i remove the sum and it's already, but my problem now is there's a lot of duplication, all in need is one store per column..014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Ahren Villalobos014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Ahwie sacrez014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Aldreen Wiena Amatorio014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Alen Arienda014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Alex Meraña Jr.014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Angelik Beltran014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Angelita Luga014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Angelyn Aban014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Ann May Andrino014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Anthony Pe014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Beverly Tandoy014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Bless Elgera014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Blessie Elgera014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Cezar Santos014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Chano Pitogo014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Chico Carag014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Christian Pitogo014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Dana dela Rosa014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) dhalia jarical014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Don Ricardo014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Dondie Ricardo014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Dulce Mia Besinio014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Elmer Mirador014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Erwin Miñano014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Evangeline Baniel014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Gay Montante014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Grace Maldonado014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Harold Ferrer014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Hazel Jimenez014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Ice Santos014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) irish jurada014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Ivy Cortez014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Jenny Kaye Mata014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Jersey Gerez014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Jesus Inaudito014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Jhapz Ebe014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) Joan Bajao014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) John Jordaen Bataclan014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) John Michael Maleniza014 ALABANG 014-12/11/2011-120408 Phone Cash 164.00 204.00 connectivity issue(phone/psi/msgtool/remote) John Paul MejiaJeneca :) |
 |
|
|
JPG
Starting Member
10 Posts |
Posted - 2011-12-23 : 02:00:51
|
| one row per store rather..Jeneca :) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-23 : 03:15:42
|
| dont remove the sum instead check data types and if non numeric you need to exclude them before applying SUM()------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|