Solved

Combine Two Fields

Posted on 2014-09-03
3
112 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 45

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now