Solved

Combine Two Fields

Posted on 2014-09-03
3
115 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 40

Expert Comment

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

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

Accepted Solution

by:
Vitor Montalvão earned 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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