Display ALL rows even if no data exists

  • sgmunson (8/19/2014)


    Just a quick FYI to make everyone aware that the posted query doesn't work with the posted table inserts, and that you'll need to add a right paren to one of the table create statements as it's missing in the posted code. The query is looking for mgd.BOOKING_OFFICE_CD, and that table does not contain such a field, nor do any of the other tables. Note also that the OP has STILL NOT EXPLAINED the relevance of the individual tables to the desired result. Thus the posted code, for all practical purposes, is useless.

    Some might complain that I had bowed out on this post, so why am I still responding? Simple, really... Between the arrogance of the OP posting the words "On popular demand", as if to indicate they had no intention of posting what was requested, and only did so when pushed into it; and the subsequent failure of the OP to even post usable code. I have to wonder if the OP is even qualified to perform the work at all...

    That kind of disrespect in a post is not particularly excusable, and I'm not going to help this poster continue to waste anyone's time any further.

    If you can see properly, I posted a smiley next to 'On popular demand' as it was intended to be in humour.

    Just to make you aware, I reported you yesterday for your provocative post and I am going to report you now again for the similar thing you have done now.

    You just CANNOT force members to not reply to a post.

    Hope you get banned soon.

  • I'm pretty sure I can't force anyone to do anything. I don't need to. Clearly, you'd rather complain than actually solve your problem. You need to realize that when you are getting free assistance, biting the hand that feeds you is a bad idea. Continually avoiding providing any useful information is also a pretty good way to stop getting help. I'm pretty sure any lack of assistance coming from other members will be appropriately proportional to your lack of respect for the value of the time of those providing such assistance.

    Steve (aka sgmunson) πŸ™‚ πŸ™‚ πŸ™‚
    Rent Servers for Income (picks and shovels strategy)

  • sgmunson (8/19/2014)


    I'm pretty sure I can't force anyone to do anything. I don't need to. Clearly, you'd rather complain than actually solve your problem. You need to realize that when you are getting free assistance, biting the hand that feeds you is a bad idea. Continually avoiding providing any useful information is also a pretty good way to stop getting help. I'm pretty sure any lack of assistance coming from other members will be appropriately proportional to your lack of respect for the value of the time of those providing such assistance.

    I am not asking for your assistance anymore so stop replying. You have done enough damage now.

  • Paul, if you wouldn't mind running through your sample script and correcting the errors which Steve kindly pointed out, I'll take a look later today.

    β€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • ChrisM@Work (8/20/2014)


    Paul, if you wouldn't mind running through your sample script and correcting the errors which Steve kindly pointed out, I'll take a look later today.

    Hi Chris,

    The sample script is working okay with the SQL query. could you please give some suggestion if you have some time.

    Thanks.

  • pwalter83 (8/25/2014)


    ChrisM@Work (8/20/2014)


    Paul, if you wouldn't mind running through your sample script and correcting the errors which Steve kindly pointed out, I'll take a look later today.

    Hi Chris,

    The sample script is working okay with the SQL query. could you please give some suggestion if you have some time.

    Thanks.

    Thanks Paul, it works for me.

    -- There are values in your hard-coded list which don't exist in the two lookup tables MG_COUNTRY and MG_OFFICE.

    -- Whilst there may be edge cases where it makes sense to supplement existing tables with hard-coded values,

    -- I suspect this is not one of them.

    -- Update the two lookup tables and we'll start again.

    SELECT *

    INTO #Offices

    FROM (VALUES

    ('KBE ANR','BELGIUM'),('KBE ZEE','BELGIUM'),('KEU ANR','BELGIUM'),

    ('KDE VIE','AUSTRIA'),

    ('KDE BRE','GERMANY'),('KDE BRV','GERMANY'),('KDE DUS','GERMANY'),('KDE FRA','GERMANY'),('KDE HAM','GERMANY'),('KDE MUC','GERMANY'),('KDE STR','GERMANY'),

    ('KFR BOD','FRANCE'),('KFR DKK','FRANCE'),('KFR FOS','FRANCE'),('KFR LEH','FRANCE'),('KFR LIO','FRANCE'),('KFR MRS','FRANCE'),

    ('KFR PAR','FRANCE'),('EXAF PARIS','FRANCE'),('FRBAL BOD','FRANCE'),('KEU LEH','FRANCE'),

    ('KEU RTM','NETHERLANDS'),('KNL RTM','NETHERLANDS'),

    ('KDE PRG','CZECH REPUBLIC'),

    ('CHGLS BSL','SWITZERLAND'),

    ('KPT LIS','PORTUGAL'),('KPT OPO','PORTUGAL'),

    ('ESBLR BCN','SPAIN'),('ESBLR MAD','SPAIN'),('ESBLR SDR','SPAIN'),('ESBLR TAR','SPAIN'),('ESBLR VCL','SPAIN'),('ESBLR VGO','SPAIN'),

    ('ESBLR VLC','SPAIN'),('KES BCN','SPAIN'),('KES BIO','SPAIN'),('KES MAD','SPAIN'),('KES VGO','SPAIN'),('KES VLC','SPAIN'),

    ('IEIRL DUB','IRELAND'),('IEIRL ORK','IRELAND'),

    ('KSE HES','SWEDEN'),('KSE-JV GOT','SWEDEN'),('KSE-JV HES','SWEDEN'),

    ('KFI HEL','FINLAND'),

    ('KDK AAL','DENMARK'),('KDK AAR','DENMARK'),('KDK CPH','DENMARK'),('KDK EBJ','DENMARK'),('KDK ODE','DENMARK'),

    ('KDK-JV AAL','DENMARK'),('KDK-JV AAR','DENMARK'),('KDK-JV CPH','DENMARK'),('KDK-JV EBJ','DENMARK'),('KDK-JV ODE','DENMARK'),

    ('KNO OSL','NORWAY'),('KNO-JV OSL','NORWAY'),

    ('KDE GDY', 'BALTIC'),('EESCR TLL', 'BALTIC'),('KRU LED', 'BALTIC'),('LTLIM KLJ', 'BALTIC'),('LVKLS RIX', 'BALTIC'),('RUMET LED', 'BALTIC'),('RUMET MOW', 'BALTIC'),('RUMSA LED','BALTIC')

    ) d (OFFICE_CD, COUNTRY_DSC)

    -- Countries missing from [dbo].[MG_COUNTRY]:

    SELECT DISTINCT COUNTRY_DSC FROM #Offices o

    WHERE NOT EXISTS (SELECT 1 FROM [dbo].[MG_COUNTRY] c WHERE c.COUNTRY_DSC = o.COUNTRY_DSC)

    -- Offices missing from [dbo].[MG_OFFICE]:

    SELECT OFFICE_CD

    FROM #Offices o

    WHERE NOT EXISTS (SELECT 1 FROM [dbo].[MG_OFFICE] d WHERE d.OFFICE_CD = o.OFFICE_CD )

    β€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • SELECTa.BOOKING_NUM,

    d.COUNTRY_DSC,

    CASE WHEN POL_LOCATION_CD IN ('DKAAR', 'DKCPH', 'FIHEL','FIKTK', 'IEORK', 'IEDUB', 'NLRTM', 'PTLEI', 'PTOPO', 'PTLIS', 'ESBIO', 'ESVGO', 'SEGOT', 'SEHEL', 'GBBEL') THEN 'NLRTM' WHEN POL_LOCATION_CD IN ('DKFRC',

    'FIRAU', 'FIOUL', 'DEBRV', 'NOAES', 'NOBGO', 'NOFRK', 'NOHAL', 'NOHAU', 'NOKRS', 'NOKSU', 'NOLAR', 'NOMSS', 'NOOSL', 'NOTAE', 'PLGDY', 'SEGVX', 'SEMMA',

    'SENRK', 'SESTO', 'DEHAM') THEN 'DEBRV' WHEN POL_LOCATION_CD = 'BEANR' THEN 'BEANR' WHEN POL_LOCATION_CD = 'FRLEH' THEN 'FRLEH' ELSE POL_LOCATION_CD END AS POL_LOCATION_CD,

    CASE WHEN a.EQUIPMENT_TYPE_CD LIKE '20%' THEN 1 WHEN a.EQUIPMENT_TYPE_CD IN ('40D96', '40R96') THEN 2 ELSE 2 END AS TEU,

    a.TYPE_CD,

    a.VESSEL_CD,

    a.VOYAGE_CD

    FROM(VALUES

    ('GERMANY'),('AUSTRIA'),('NETHERLANDS'),('BELGIUM'),('FRANCE'),

    ('IRELAND'),('SWEDEN'),('FINLAND'),('DENMARK'),('NORWAY'),('CZECH REPUBLIC'),('SWITZERLAND'),('PORTUGAL'),('SPAIN'),('BALTICS'),('BUFFER')

    ) d (COUNTRY_DSC)

    LEFT JOIN (

    SELECTmgd.BOOKING_NUM,

    CASE WHEN mo.OFFICE_CD IN ('KBE ANR','KBE ZEE', 'KEU ANR') THEN 'BELGIUM'

    WHEN mo.OFFICE_CD IN ('KDE VIE') THEN 'AUSTRIA'

    WHEN mo.OFFICE_CD IN ('KDE BRE', 'KDE BRV', 'KDE DUS', 'KDE FRA', 'KDE HAM', 'KDE MUC', 'KDE STR') THEN 'GERMANY'

    WHEN mo.OFFICE_CD IN ('KFR BOD','KFR DKK','KFR FOS','KFR LEH','KFR LIO','KFR MRS','KFR PAR','EXAF PARIS','FRBAL BOD','KEU LEH') THEN 'FRANCE'

    WHEN mo.OFFICE_CD IN ('KEU RTM', 'KNL RTM') THEN 'NETHERLANDS'

    WHEN mo.OFFICE_CD IN ('KDE PRG') THEN 'CZECH REPUBLIC'

    WHEN mo.OFFICE_CD IN ('CHGLS BSL') THEN 'SWITZERLAND'

    WHEN mo.OFFICE_CD IN ('KPT LIS','KPT OPO') THEN 'PORTUGAL'

    WHEN mo.OFFICE_CD IN ('ESBLR BCN','ESBLR MAD','ESBLR SDR','ESBLR TAR','ESBLR VCL','ESBLR VGO','ESBLR VLC','KES BCN','KES BIO','KES MAD','KES VGO','KES VLC') THEN 'SPAIN'

    WHEN mo.OFFICE_CD IN ('IEIRL DUB','IEIRL ORK') THEN 'IRELAND'

    WHEN mo.OFFICE_CD IN ('KSE HES','KSE-JV GOT','KSE-JV HES') THEN 'SWEDEN'

    WHEN mo.OFFICE_CD IN ('KFI HEL') THEN 'FINLAND'

    WHEN mo.OFFICE_CD IN ('KDK AAL','KDK AAR','KDK CPH','KDK EBJ','KDK ODE','KDK-JV AAL','KDK-JV AAR','KDK-JV CPH','KDK-JV EBJ','KDK-JV ODE') THEN 'DENMARK'

    WHEN mo.OFFICE_CD IN ('KNO OSL','KNO-JV OSL') THEN 'NORWAY'

    WHEN mo.OFFICE_CD IN ('KDE GDY', 'EESCR TLL', 'KRU LED', 'LTLIM KLJ', 'LVKLS RIX', 'RUMET LED', 'RUMET MOW', 'RUMSA LED') THEN 'BALTIC' ELSE 'BUFFER' END AS COUNTRY_DSC,

    mgd.POL_LOCATION_CD,

    ber.EQUIPMENT_TYPE_CD,

    mcc.TYPE_CD,

    mbi.VESSEL_CD, mbi.VOYAGE_CD

    FROMMG_BOOKING_ITINERARY mbi

    JOIN MG_BOOKING mgd ON mgd.BOOKING_ID = mbi.BOOKING_ID

    JOIN MG_BOOKING_EQUIPMENT_REQ_DETAIL ber ON ber.BOOKING_ID = mgd.BOOKING_ID

    JOIN MG_CONTAINER_CODE mcc ON mcc.CONTAINER_CD = ber.EQUIPMENT_TYPE_CD

    JOIN MG_OFFICE mo ON mo.OFFICE_CD = mgd.BOOKING_OFFICE_CD

    WHEREmbi.VESSEL_CD IN ('HPHO') AND mbi.VOYAGE_CD IN ('121W')

    ) a

    ON d.COUNTRY_DSC = a.COUNTRY_DSC

    ORDER BY d.COUNTRY_DSC

    Far away is close at hand in the images of elsewhere.
    Anon.

  • David Burrows (8/26/2014)


    SELECTa.BOOKING_NUM,

    d.COUNTRY_DSC,

    CASE WHEN POL_LOCATION_CD IN ('DKAAR', 'DKCPH', 'FIHEL','FIKTK', 'IEORK', 'IEDUB', 'NLRTM', 'PTLEI', 'PTOPO', 'PTLIS', 'ESBIO', 'ESVGO', 'SEGOT', 'SEHEL', 'GBBEL') THEN 'NLRTM' WHEN POL_LOCATION_CD IN ('DKFRC',

    'FIRAU', 'FIOUL', 'DEBRV', 'NOAES', 'NOBGO', 'NOFRK', 'NOHAL', 'NOHAU', 'NOKRS', 'NOKSU', 'NOLAR', 'NOMSS', 'NOOSL', 'NOTAE', 'PLGDY', 'SEGVX', 'SEMMA',

    'SENRK', 'SESTO', 'DEHAM') THEN 'DEBRV' WHEN POL_LOCATION_CD = 'BEANR' THEN 'BEANR' WHEN POL_LOCATION_CD = 'FRLEH' THEN 'FRLEH' ELSE POL_LOCATION_CD END AS POL_LOCATION_CD,

    CASE WHEN a.EQUIPMENT_TYPE_CD LIKE '20%' THEN 1 WHEN a.EQUIPMENT_TYPE_CD IN ('40D96', '40R96') THEN 2 ELSE 2 END AS TEU,

    a.TYPE_CD,

    a.VESSEL_CD,

    a.VOYAGE_CD

    FROM(VALUES

    ('GERMANY'),('AUSTRIA'),('NETHERLANDS'),('BELGIUM'),('FRANCE'),

    ('IRELAND'),('SWEDEN'),('FINLAND'),('DENMARK'),('NORWAY'),('CZECH REPUBLIC'),('SWITZERLAND'),('PORTUGAL'),('SPAIN'),('BALTICS'),('BUFFER')

    ) d (COUNTRY_DSC)

    LEFT JOIN (

    SELECTmgd.BOOKING_NUM,

    CASE WHEN mo.OFFICE_CD IN ('KBE ANR','KBE ZEE', 'KEU ANR') THEN 'BELGIUM'

    WHEN mo.OFFICE_CD IN ('KDE VIE') THEN 'AUSTRIA'

    WHEN mo.OFFICE_CD IN ('KDE BRE', 'KDE BRV', 'KDE DUS', 'KDE FRA', 'KDE HAM', 'KDE MUC', 'KDE STR') THEN 'GERMANY'

    WHEN mo.OFFICE_CD IN ('KFR BOD','KFR DKK','KFR FOS','KFR LEH','KFR LIO','KFR MRS','KFR PAR','EXAF PARIS','FRBAL BOD','KEU LEH') THEN 'FRANCE'

    WHEN mo.OFFICE_CD IN ('KEU RTM', 'KNL RTM') THEN 'NETHERLANDS'

    WHEN mo.OFFICE_CD IN ('KDE PRG') THEN 'CZECH REPUBLIC'

    WHEN mo.OFFICE_CD IN ('CHGLS BSL') THEN 'SWITZERLAND'

    WHEN mo.OFFICE_CD IN ('KPT LIS','KPT OPO') THEN 'PORTUGAL'

    WHEN mo.OFFICE_CD IN ('ESBLR BCN','ESBLR MAD','ESBLR SDR','ESBLR TAR','ESBLR VCL','ESBLR VGO','ESBLR VLC','KES BCN','KES BIO','KES MAD','KES VGO','KES VLC') THEN 'SPAIN'

    WHEN mo.OFFICE_CD IN ('IEIRL DUB','IEIRL ORK') THEN 'IRELAND'

    WHEN mo.OFFICE_CD IN ('KSE HES','KSE-JV GOT','KSE-JV HES') THEN 'SWEDEN'

    WHEN mo.OFFICE_CD IN ('KFI HEL') THEN 'FINLAND'

    WHEN mo.OFFICE_CD IN ('KDK AAL','KDK AAR','KDK CPH','KDK EBJ','KDK ODE','KDK-JV AAL','KDK-JV AAR','KDK-JV CPH','KDK-JV EBJ','KDK-JV ODE') THEN 'DENMARK'

    WHEN mo.OFFICE_CD IN ('KNO OSL','KNO-JV OSL') THEN 'NORWAY'

    WHEN mo.OFFICE_CD IN ('KDE GDY', 'EESCR TLL', 'KRU LED', 'LTLIM KLJ', 'LVKLS RIX', 'RUMET LED', 'RUMET MOW', 'RUMSA LED') THEN 'BALTIC' ELSE 'BUFFER' END AS COUNTRY_DSC,

    mgd.POL_LOCATION_CD,

    ber.EQUIPMENT_TYPE_CD,

    mcc.TYPE_CD,

    mbi.VESSEL_CD, mbi.VOYAGE_CD

    FROMMG_BOOKING_ITINERARY mbi

    JOIN MG_BOOKING mgd ON mgd.BOOKING_ID = mbi.BOOKING_ID

    JOIN MG_BOOKING_EQUIPMENT_REQ_DETAIL ber ON ber.BOOKING_ID = mgd.BOOKING_ID

    JOIN MG_CONTAINER_CODE mcc ON mcc.CONTAINER_CD = ber.EQUIPMENT_TYPE_CD

    JOIN MG_OFFICE mo ON mo.OFFICE_CD = mgd.BOOKING_OFFICE_CD

    WHEREmbi.VESSEL_CD IN ('HPHO') AND mbi.VOYAGE_CD IN ('121W')

    ) a

    ON d.COUNTRY_DSC = a.COUNTRY_DSC

    ORDER BY d.COUNTRY_DSC

    Actually this worked superbly well for the OP ! I had been stuck on this for a long time now and had given up all hope. Thankfully your wonderful solution came to the rescue ! Cheers !

  • pwalter83 (8/26/2014)


    Actually this worked superbly well for the OP ! I had been stuck on this for a long time now and had given up all hope

    You're welcome πŸ™‚

    As an added note (and as already mentioned by Chris) supplementing the hard coded lookups with tables could ease future changes / additions.

    Far away is close at hand in the images of elsewhere.
    Anon.

  • ChrisM@Work (8/26/2014)


    pwalter83 (8/25/2014)


    ChrisM@Work (8/20/2014)


    Paul, if you wouldn't mind running through your sample script and correcting the errors which Steve kindly pointed out, I'll take a look later today.

    Hi Chris,

    The sample script is working okay with the SQL query. could you please give some suggestion if you have some time.

    Thanks.

    Thanks Paul, it works for me.

    Thanks Chris, I guess this issue is resolved. Thanks for your help all the way.

  • David Burrows (8/26/2014)


    pwalter83 (8/26/2014)


    Actually this worked superbly well for the OP ! I had been stuck on this for a long time now and had given up all hope

    You're welcome πŸ™‚

    As an added note (and as already mentioned by Chris) supplementing the hard coded lookups with tables could ease future changes / additions.

    Thanks David, will try to implement this suggestion from Chris.

  • David Burrows (8/26/2014)


    pwalter83 (8/26/2014)


    Actually this worked superbly well for the OP ! I had been stuck on this for a long time now and had given up all hope

    You're welcome πŸ™‚

    As an added note (and as already mentioned by Chris) supplementing the hard coded lookups with tables could ease future changes / additions.

    ---------------------------------------------------------------------

    -- Missing stuff from tables:

    ---------------------------------------------------------------------

    SELECT COUNTRY_CD, COUNTRY_DSC

    INTO #MG_COUNTRY

    FROM [dbo].[MG_COUNTRY]

    UNION ALL

    SELECT * FROM (VALUES

    ('AT','AUSTRIA'),('BX','BALTIC'),('CZ','CZECH REPUBLIC'),('DK','DENMARK'),('FI','FINLAND'),

    ('DE','GERMANY'),('IE','IRELAND'),('NO','NORWAY'),('PT','PORTUGAL'),('CH','SWITZERLAND'),

    ('FF','BUFFER')

    ) d (COUNTRY_CD, COUNTRY_DSC)

    SELECT OFFICE_CD, COUNTRY_CD

    INTO #MG_OFFICE

    FROM [dbo].[MG_OFFICE]

    UNION ALL

    SELECT OFFICE_CD, COUNTRY_CD

    FROM (VALUES

    ('KDE VIE', 'AT'),('KDE BRV', 'DE'),('KDE MUC', 'DE'),('KDE STR', 'DE'),('KFR MRS', 'FR'),('KFR PAR', 'FR'),

    ('EXAF PARIS', 'FR'),('FRBAL BOD', 'FR'),('KEU LEH', 'FR'),('KDE PRG', 'CZ'),('CHGLS BSL', 'CH'),('KPT LIS', 'PT'),

    ('KPT OPO', 'PT'),('ESBLR VCL', 'ES'),('ESBLR VGO', 'ES'),('ESBLR VLC', 'ES'),('KES BCN', 'ES'),('KES BIO', 'ES'),

    ('KES MAD', 'ES'),('KES VGO', 'ES'),('KES VLC', 'ES'),('IEIRL DUB', 'IE'),('IEIRL ORK', 'IE'),('KFI HEL', 'FI'),

    ('KDK AAL', 'DK'),('KDK AAR', 'DK'),('KDK CPH', 'DK'),('KDK EBJ', 'DK'),('KDK ODE', 'DK'),('KDK-JV AAL', 'DK'),

    ('KDK-JV AAR', 'DK'),('KDK-JV CPH', 'DK'),('KDK-JV EBJ', 'DK'),('KDK-JV OD', 'DK'),('KNO OSL', 'NO'),('KNO-JV OSL', 'NO'),

    ('LVKLS RIX', 'BX'),('RUMET LED', 'BX'),('RUMET MOW', 'BX'),('RUMSA LED', 'BX')

    ) d (OFFICE_CD, COUNTRY_CD)

    ----

    SELECTa.BOOKING_NUM,

    d.COUNTRY_DSC,

    CASE WHEN POL_LOCATION_CD IN ('DKAAR', 'DKCPH', 'FIHEL','FIKTK', 'IEORK', 'IEDUB', 'NLRTM', 'PTLEI', 'PTOPO', 'PTLIS', 'ESBIO', 'ESVGO', 'SEGOT', 'SEHEL', 'GBBEL') THEN 'NLRTM' WHEN POL_LOCATION_CD IN ('DKFRC',

    'FIRAU', 'FIOUL', 'DEBRV', 'NOAES', 'NOBGO', 'NOFRK', 'NOHAL', 'NOHAU', 'NOKRS', 'NOKSU', 'NOLAR', 'NOMSS', 'NOOSL', 'NOTAE', 'PLGDY', 'SEGVX', 'SEMMA',

    'SENRK', 'SESTO', 'DEHAM') THEN 'DEBRV' WHEN POL_LOCATION_CD = 'BEANR' THEN 'BEANR' WHEN POL_LOCATION_CD = 'FRLEH' THEN 'FRLEH' ELSE POL_LOCATION_CD END AS POL_LOCATION_CD,

    CASE WHEN a.EQUIPMENT_TYPE_CD LIKE '20%' THEN 1 WHEN a.EQUIPMENT_TYPE_CD IN ('40D96', '40R96') THEN 2 ELSE 2 END AS TEU,

    a.TYPE_CD,

    a.VESSEL_CD,

    a.VOYAGE_CD

    FROM #MG_COUNTRY d

    LEFT JOIN (

    SELECTmgd.BOOKING_NUM,

    mo.COUNTRY_CD,

    mgd.POL_LOCATION_CD,

    ber.EQUIPMENT_TYPE_CD,

    mcc.TYPE_CD,

    mbi.VESSEL_CD, mbi.VOYAGE_CD

    FROMMG_BOOKING_ITINERARY mbi

    JOIN MG_BOOKING mgd ON mgd.BOOKING_ID = mbi.BOOKING_ID

    JOIN MG_BOOKING_EQUIPMENT_REQ_DETAIL ber ON ber.BOOKING_ID = mgd.BOOKING_ID

    JOIN MG_CONTAINER_CODE mcc ON mcc.CONTAINER_CD = ber.EQUIPMENT_TYPE_CD

    JOIN #MG_OFFICE mo ON mo.OFFICE_CD = mgd.BOOKING_OFFICE_CD

    WHEREmbi.VESSEL_CD IN ('HPHO') AND mbi.VOYAGE_CD IN ('121W')

    ) a

    ON d.COUNTRY_CD = a.COUNTRY_CD

    ORDER BY d.COUNTRY_DSC

    β€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 12 posts - 46 through 56 (of 56 total)

You must be logged in to reply to this topic. Login to reply