explain query

  • can anybody explain what exactly is happening in this query?

    Thanks in advance,

    create table abc1 AS (

    Select y.*, (endDateTime - Startdatetime) as TotalHrs

    From (

    select repID, BeginningOfDay, EndOfDay, calendar_date, clockin_date, clockout_date, clockin_time, clockout_time,

    (case when (clockout_date||' '||clockout_time)::Timestamp > EndOfDay

    then EndOfDay

    else (clockout_date|| ' '||clockout_time)::Timestamp

    end) as EndDateTime,

    (case when (clockin_date||' '||clockin_time)::Timestamp < BeginningOfDay

    then BeginningOfDay

    else (Clockin_date||' '||Clockin_time)::Timestamp

    end) as StartDateTime,

    DMiles

    From (

    select repID, (calendar_date||' '||'00:00:00')::Timestamp as BeginningOfDay, (calendar_date||' '||'23:59:59')::Timestamp as EndOfDay, calendar_date, clockin_date, clockout_date, clockin_time, clockout_time, DeviceMiles

    from fact_clockdeviceMiles a

    join dim_cabcffer b on

    calendar_date >= clockin_date and

    calendar_date <= clockout_date

    where calendar_date is NOT NULL

    order by calendar_date

    ) z

    ) y

  • That's creating a table with the data returned by the query. The datatypes are defined by the column data types or the expressions used in the query.

    That's not a SQL Server query and it's probably Oracle or PostgreSQL.

    In SQL Server we use SELECT column_list INTO NewTable FROM Sometables.

    Why do I mention the SQL Server syntax? Because this is a SQL Server site. 😎

    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

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

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