SQL File Tracking Query

  • Hi
    Everyday some vendor files will be loaded into db and we are in process to create control report in place.  I need small help

    create table dbo.test
    (
    Vendor_Name CHAR(100),
    File_Count INT
    )
    INSERT INTO dbo.test values ('V1',10),('V2',0),('V3',10),('V4',30),('V5',50)

    1) We will consider V1 as one vendor and remaining all as one  vendor
    2) if data is not loaded then we need to derive indictor as 0 or 1 

    Output
    Vendor Name     FileRecevied
    V1file                    1
    Allother                 0 (as we are not received data for v2 -- all vendor's are combined as one except V1- if one file data is not then we need to show as 0)

    I hope this is clear, if any questions, Please let me know thanks!

  • DECLARE @vendors table( Id int IDENTITY, VendorName varchar(100) );
    INSERT @vendors ( VendorName )
    VALUES          ( 'V1' )
         ,          ( 'V2' )
         ,          ( 'V3' )
         ,          ( 'V4' )
         ,          ( 'V5' )
         ,          ( 'V6' );
    DECLARE @test-2 table ( VendorId int, FileCount INT );
    INSERT INTO @test-2
    VALUES (1,10)
         , (3,10)
         , (4,30)
         , (5,50);
    SELECT VendorName, Coalesce(t.FileCount, 0) FileCount
    FROM @vendors v
    LEFT JOIN @test-2 t ON v.Id = t.VendorId;

  • koti.raavi - Thursday, May 17, 2018 10:51 AM

    Hi
    Everyday some vendor files will be loaded into db and we are in process to create control report in place.  I need small help

    create table dbo.test
    (
    Vendor_Name CHAR(100),
    File_Count INT
    )
    INSERT INTO dbo.test values ('V1',10),('V2',0),('V3',10),('V4',30),('V5',50)

    1) We will consider V1 as one vendor and remaining all as one  vendor
    2) if data is not loaded then we need to derive indictor as 0 or 1 

    Output
    Vendor Name     FileRecevied
    V1file                    1
    Allother                 0 (as we are not received data for v2 -- all vendor's are combined as one except V1- if one file data is not then we need to show as 0)

    I hope this is clear, if any questions, Please let me know thanks!

    What do you need help with? You have not asked a question!

    Where do the vendor names come from?
    What is the link between a vendor and their files?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

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

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