Table Join with Grouping problem

  • Morning,
    I'm looking for some help on my query, it really a grouping problem.
    I've joined 2 unsimilar tables (different db's)  to get a value not available in the 1st table. 

    The 2nd table has different values per product which when grouped together splits my records...

    select y.Destination, count(*) Loads , sum(y.NetTons) Tons,   t.product
    ,CASE DATEPART(day ,GETDATE())
     when 1 then t.[1st]
     when 2 then t.[2nd]
     when 3 then t.[3rd]
    end EXPT
    FROM [SZ2611308].[dbo].[RSILoadoutTransaction] y
    inner Join [AZUREDB].[SSSUTIL].[dbo].[SA-Releases] t on y.Destination = t.customer
    WHERE [TransactionDate] > DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
    and t. customer is not null
    and t. [1st] is not null
    and t. [2nd] is not null
    and t. [3rd] is not null

    GROUP BY y.Destination, t.[1st], t.[2nd], t.[3rd], t.product

    This next image is the correct format I need but without the [expt] value

    Thanks for your help !
    Greg

  • Your GROUP BY includes product, and your picture shows two different values for product for destination BJS.   That would cause your problem.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

Viewing 2 posts - 1 through 1 (of 1 total)

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