Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Combine Two Fields

Posted on 2014-09-03
3
Medium Priority
?
121 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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…

670 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