Forum Replies Created

Viewing 15 posts - 181 through 195 (of 1,419 total)

  • Reply To: Sample between two dates for two date ranges ???

    The date columns are of data type DATE? It's not confirmed by question. For this answer the dates must be stored as DATE.

    ;with example_cte as (
    ...

    • This reply was modified 2 years, 9 months ago by Steve Collins. Reason: Removed two unnecessary pairs of parentheses

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: How to find second position after decimal

    Thank you Jeff.  44.9% or 31%?  Either way there's no implicit type conversion 🙂

    Ken McKelvey's solution in the "Pivot with grouping intervals" topic is interesting.  It cross join's a 2...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Pivot with grouping internvals

    The top two CTEs could be replaced with only one.  Possibly the bottom two could be combined as well using the "smudge" method?

    with 
    pvt_cte as (
    ...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Pivot with grouping internvals

    Afaik this returns the same output.  The CTEs expand the date intervals, pivot by role name and summarize by day, identify gaps in GROUP BY columns, and create groups using...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Insert records based on value

    From your query results you could CROSS APPLY a row generator created by using the row cardinality from sys.all_columns (which in my test instance is 11,745 rows) and TOP.  The...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: How to find second position after decimal

    You could test if the modulo .1 of HRS equals zero

    ;WITH cte_data AS (
    SELECT CAST(50.10 AS numeric(5, 2)) AS HRS
    ...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: convert to date from datetime

    Also there's EOMONTH which has an optional second parameter 'offset'.  Regardless of which date/datetime datatype is passed to the EOMONTH function it returns DATE.  Ha, some SSC members were wondering...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: How to find ultimate parent

    All perfect parents have the same thing in common.  No kids

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Can’t return role based on employee no from three columns?

    Also my code assumes the RequestNo is UNIQUE NOT NULL and has appropriate sequential values.  The DDL provided says the RequestNo is NULL-able

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Can’t return role based on employee no from three columns?

    drop TABLE  if exists #F6000059;
    go
    CREATE TABLE #F6000059
    (
    [RequestNo] [int] NULL,
    [REAN82] [int] NULL,
    [REAN83] [int] NULL,
    ...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: SQL Query help

    It seems like you're looking for an UPDATE statement

    /* select using OUTER APPLY and TOP(1) */
    select t.id, t.code, t.result, prev.result prev_result,
    ...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Time intervals with Number of Employees

    Alfred wrote:

    ...

    In source table each row is allways for one date, so if the work shift continues over midnight it's broken into two parts. But for expected output the time...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Loop query help

    rocky_498 wrote:

    Thanks, Drew for your reply. Did you bother to read my latest post? and did you bother to run the query that I provided?

    IF yes, then my question was...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Loop query help

    drew.allen wrote:

    I also did a comparison of my query with Steve's query.  Here are the read stats.  Specifically note the scan counts and logical reads on the 'Worktable'.

    Using the preceding...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Loop query help

    Afaik the set up is not clear.  This seems to produce the correct result

    with
    gaps_cte as (
    select *, case when crit<>lag(crit) over (order by...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

Viewing 15 posts - 181 through 195 (of 1,419 total)