Forum Replies Created

Viewing 15 posts - 346 through 360 (of 4,085 total)

  • Reply To: How to update a record by checking a value in another record in same table

    When posting to an international forum, it is best to use a date that is internationally recognized.  ISO suggests using YYYYMMDD, but YYYY-MM-DD is acceptable alternative.

    What is so special about...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Introduction to the Partition By Window Function

    The main argument I have with this article is that he uses frames without ever defining the term.  Also, I've never found a need to use the frame UNBOUNDED PRECEDING...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: SSMS - Results Tab - Keyboard Shortcut

    You are just as capable of Googling this as any of us.  SSMS is designed for writing queries, not manipulating the results, so I'm not optimistic that you will find...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: ? List all tables used in stored procedures and views ?

    You're looking for the table-valued functions sys.dm_sql_referenced_entities() and sys.dm_sql_referencing_entities().  These will not show cross database dependencies.  You may also want to look at Redgate's SQL Dependency Tracker 3.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: SQL query help

    This is just BAD table design.  You'd be better off totally redesigning this process.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Understanding the use of a CTE with MERGE

    below86 is wrong about how the CTE works.  A CTE is not a temp table, but rather a temp view, and (just like a view) you can update the underlying...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Query to report on claim frequency per year and quarter

    I think the following is the best approach:

    1. Use a tally table add a specific number of quarters to the purchase date.

      • Use range 0-17 so that you include both...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: NOOB question with Case statement

    MVDBA (Mike Vessey) wrote:

    DesNorton wrote:

    This looks like you are trying to do an UPDATE. If so, then

    UPDATE  YourTable
    SET columnB = CASE
    ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Need help query for current row and previous row

    inkosi_dba_dev wrote:

    Drew,

    To better understand can you please supply a re-structured query that would achieve the same results. This would help to put a method to result

    You learn more by trying...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Need help query for current row and previous row

    In case you're not aware LEAD(WhatWeight,1) OVER (ORDER BY WeightDte desc) is equivalent to LAG(WhatWeight,1) OVER (ORDER BY WeightDte).  In this case, it is right to use LEAD() because the sort...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Finding out mismatch between time lines.

    This may perform better.  It's hard to tell with such a small sample size.

    WITH data_dates AS
    (
    SELECT s.PlanId, dt.dt
    FROM #Source AS s
    CROSS APPLY (VALUES(s.StartDate), (DATEADD(DAY, 1, s.EndDate)) )...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: getdate() to east time

    Jeffrey Williams wrote:

    SELECT getdate() AT TIME ZONE 'Eastern Standard Time';

    This will only work if the local time IS Eastern Standard Time.  If the input date doesn't already have an...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: getdate() to east time

    You should be using SYSDATETIMEOFFSET() if you are going to be switching time zones.

    SELECT GETDATETIMEOFFSET() AT TIME ZONE 'US Eastern Standard Time'

    If you need to, you can...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Range of values not from a table

    Google "gaps and islands problem".  Using that approach should perform better than joining to a numbers table, especially if the number of missing ids is very small relative to the...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Max window function with order by

    Certain windowed functions require a frame when there is an ORDER BY clause.  MAX() is one of those functions.  So MAX(t.end_date) OVER (PARTITION BY t.customer_id ORDER BY t.start_Date ) AS...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 15 posts - 346 through 360 (of 4,085 total)