Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Combine Two Fields

Posted on 2014-09-03
3
Medium Priority
?
122 Views
Last Modified: 2014-09-03
Hi

How can I combine the bcClass.Description and bcBrands.Description fields into one field. There will only be a value in on of the two fields.

SELECT        bcGraderings.Aantal AS Qty, bcGraderings.Class AS sClass, bcGraderings.MG AS MassGrp, bcGraderings.Mass, bcGraderings.Product, bcGraderings.ISO AS Salesbrand, bcClass.Description, 
                         bcBrands.Description AS Expr1
FROM            bcGraderings LEFT OUTER JOIN
                         bcBrands ON bcGraderings.ISO = bcBrands.Code LEFT OUTER JOIN
                         bcClass ON bcGraderings.ISO = bcClass.Code
WHERE        (bcGraderings.gDate > '2014-09-01 00:00:00.000')

Open in new window


Here is an example of the data that is returned with the query

Qty      sClass      MassGrp      Mass      Product      Salesbrand      Description      Expr1
1      M      2      14      SA1      M      Group 1      NULL
1      M      1      8,5      SA1      M      Group 1      NULL
1      M      1      11,5      SA0      M      Group 2      NULL
1      M      4      22      SC2      M      Group 2      NULL
1      D      3      16,5      SA2      N      NULL      Class 1
1      D      3      16,8      SA2      N      NULL      Class 2
0
Comment
Question by:Yeaktom
3 Comments
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 40301241
you can use isnull.

select isnull(bcClass.Description, bcBrands.Description) Description
0
 
LVL 52

Accepted Solution

by:
Vitor Montalvão earned 2000 total points
ID: 40301245
Like this:
SELECT        bcGraderings.Aantal AS Qty, bcGraderings.Class AS sClass, bcGraderings.MG AS MassGrp, bcGraderings.Mass, bcGraderings.Product, bcGraderings.ISO AS Salesbrand, ISNULL(bcClass.Description,                          bcBrands.Description) AS Description
FROM            bcGraderings LEFT OUTER JOIN
                         bcBrands ON bcGraderings.ISO = bcBrands.Code LEFT OUTER JOIN
                         bcClass ON bcGraderings.ISO = bcClass.Code
WHERE        (bcGraderings.gDate > '2014-09-01 00:00:00.000')

Open in new window

0
 
LVL 2

Author Closing Comment

by:Yeaktom
ID: 40301256
Again, Thanks Vitor.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question