• Luis Cazares (11/22/2013)


    Why are you inserting into a table variable and then selecting from it instead of doing the select directly as you do with your original query?

    Sean, I can't see why you say that it's Oracle. The queries look like SQL Server and I suppose Luka is using user defined data types.

    Didn't think about user defined datatypes. 😛 I was helping the same OP yesterday and it was a mix of Oracle and Sql.

    I agree with your question of why insert into a temp table to just turn around and pull it back out.

    Also, the date variable population can be made a lot simpler.

    DECLARE @startdate datetime = '2013-05-24 20:00:00'

    There is no need to format a string to that is the same format as the string itself which can be cast to a datetime as is.

    All that being said, it looks like there should be no issue with the code. But we can't actually load this to test on our systems because of the datatypes.

    _______________________________________________________________

    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/