SQL Query

  • I have table called Tracking_changes which contain 5 columns and 5th column as getdate

    I want to get the output ONLY with differences in other column 3 and 4 and getdate with group by

    We enter data on daily basis and getdate will capture the data for given date so I need Output for any changes on other column with group by getdate.

    Nita

  • I got confused with your explanation. Could you post DDL and sample data (as insert statements) along with expected results based on that sample data?

    That will give you better and faster answers.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • This is the Data I have in my table

    NameIDGradesecSystem Date

    sac11A1/5/2012

    paul21A1/5/2012

    Simon32B1/5/2012

    Kelly42B1/5/2012

    Nimo52B1/5/2012

    sac11A1/4/2013

    paul22A1/4/2013

    Simon32B1/4/2013

    Kelly42B1/4/2013

    Nimo53C1/4/2013

    OUTPUT I am expecting below (since only Grade and Sec I am concern about from System Date change)

    NameIDGradesecSystem Date

    sac11A1/4/2013

    Nimo53C1/4/2013

  • Let me give with Example:

    I have table called Tracking_changes which contain 4 columns a

    I want to get the output ONLY with differences in other column 2 and 3 and System Date with group by

    In Tracking_Changes I have data with

    NameIDGradesecSystem Date

    sac11A1/5/2012

    paul21A1/5/2012

    Simon32B1/5/2012

    Kelly42B1/5/2012

    Nimo52B1/5/2012

    sac11A1/4/2013

    paul22A1/4/2013

    Simon32B1/4/2013

    Kelly42B1/4/2013

    Nimo53C1/4/2013

    I am expecting OUTPUT with grade changes and Sec ONLY on the same table

    NameIDGradesecSystem Date

    sac11A1/4/2013

    Nimo53C1/4/2013

  • It's still not clear what you're trying to get at here. What do you mean differences in column 2 and 3? Are you referring to the columns Grade and Sec? It would be clearer if you call them by their names. And what do you mean by difference? Are you trying to compare these rows over time? To eachother? What is the criteria for rows not being returned, vs being returned?

    Executive Junior Cowboy Developer, Esq.[/url]

  • Nita Reddy (1/15/2015)


    Let me give with Example:

    I have table called Tracking_changes which contain 4 columns a

    I want to get the output ONLY with differences in other column 2 and 3 and System Date with group by

    In Tracking_Changes I have data with

    NameIDGradesecSystem Date

    sac11A1/5/2012

    paul21A1/5/2012

    Simon32B1/5/2012

    Kelly42B1/5/2012

    Nimo52B1/5/2012

    sac11A1/4/2013

    paul22A1/4/2013

    Simon32B1/4/2013

    Kelly42B1/4/2013

    Nimo53C1/4/2013

    I am expecting OUTPUT with grade changes and Sec ONLY on the same table

    NameIDGradesecSystem Date

    sac11A1/4/2013

    Nimo53C1/4/2013

    For sac above, there are no such changes so I don't understand why it's included in your example output.

    For Paul, there are changes and don't understand why it's not included in your example output.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Just to help restate the task in more formal way let's start with this (not tested due to lack of DDL and sample data script)

    -- Date interval params

    declare @sd date ='20130101';

    declare @ed date ='20150101';

    -- get a set of (Name, ID)s which have any changes in Grade or sec

    -- over the interval

    select Name, ID

    from Tracking_changes

    where Systemdate between @sd and @ed

    group by Name, ID

    having max(Grade) <> min(Grade) or max(sec) <> min(sec);

    Is it a step in right direction?

Viewing 7 posts - 1 through 6 (of 6 total)

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