• CELKO (2/2/2015)


    >> I need some help building a query. I have a table with 4 columns and need to try and put the times together. <<

    And thanks to your bad manners, we have no DDL! The ASCII picture you did post has every column wrong. The temporal model is also wrong; a (start_timestamp, end_timestamp) interval pair is never split over multiple rows. And we use ISO-8601 temporal format, not that silly local dialect you had. You used AM-PM in the 21-st century! You failed to use ISO-8601 dates!

    >> There are some inconsistencies with this, and I'm hoping to exclude them. Here is a sample table: <<

    So you admit to making us work with garbage data! So polite of you! This is the idiom for temporal data, I am not going to your job for you; give us the data and a spec, and we will help you.

    CREATE TABLE Garbage

    (emp_id CHAR(1) NOT NULL,

    event_type SMALLINT NOT NULL -– bad choice of data type

    CHECK (event_type IN (1,2)),

    in_something_timestamp DATETIME2(0) NOT NULL,

    out_something_timestamp DATETIME2(0), -- null is still active

    CHECK (in_something_timestamp < out_something_timestamp)

    );

    >> Basically what I need to do is take the time from rows with non_relational_function_flg 1 and match it with non_relational_function_flg 2 so I can get a total time of the clock in. <<

    NO! They are part of a single interval data type.

    > I'm basically trying to get totals for each Clock In-Out type. I hope I made some sense with this. <<

    No, but it tells us that you never read a single book on SQL, Data modeling or RDBMS. The INTERVAL data type is a fundamental concept. Please stop programming until you have the fundamental concepts; you are dangerous to your employer.

    Did your boss do this to you? You can only fail. It is time to quit and update the resume.

    Good grief Joe!!! Do you ever offer anything constructive or are you always the guy nobody wants around because he such an old curmudgeon???

    I agree this question lacks a lot of things to help us help them but your approach lacks anything resembling help. How do you know this person created these structures? Maybe this person is pretty new and is working an older boss who mandated this is the way to do it "because they have been doing it for so long and it is the only right way".

    Do you just always assume that every single person on the planet who has to interact with sql server should have the same level of experience as you do? Here's a news flash Joe, there aren't many people still alive that has been working with this technology longer than you have. With so much knowledge and expertise it is such a shame that you just irritate and put people down instead of actually trying to help them learn.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/