Forum Replies Created

Viewing 15 posts - 196 through 210 (of 4,085 total)

  • Reply To: Using LAG to return prior non null value

    Jonathan AC Roberts wrote:

    drew.allen wrote:

    Here is a comparison of the two methods:

    /* Windowed Aggregate (MAX)  */Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: QUERY HELP

    Jeff Moden wrote:

    I just did a deep dive on that code.  ANSI NULLs are the key there!  Really cool code!  Thanks, again, Drew.  Do you have a link where Itzik provides...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Using LAG to return prior non null value

    Here is a comparison of the two methods:

    /* Windowed Aggregate (MAX)  */
    Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Using LAG to return prior non null value

    As a side note, there is no way to implement this using just LAG(), since 2022-07-01 can only be the immediate predecessor of one record and you would need it...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Using LAG to return prior non null value

    I believe that this gives you your desired results.  It's based on code by Itzik Ben-Gan.  I prefer to use BINARY rather than CHAR except in the case of DATE...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Query Help

    Please don't cross post.  It fragments the replies.  Other thread https://www.sqlservercentral.com/forums/topic/query-help-299#post-4072505

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: QUERY HELP

    I believe that this code is faster.  It's based on code by Itzik Ben-Gan.

    SELECT ID
    , t.VAL
    , CAST(SUBSTRING(MAX(CAST(ID...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: How To Refactor Code with CTE Pt3

    • My first thought is that you shouldn't refactor code just to use a shiny new toy.
    • My second thought is that it already uses a CTE (two in fact),...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: IF ELSEIF Else issue with mysql

    First, this website is specifically dedicated to Transact SQL.  You might be better off posting to a website specifically for mySQL or to a general SQL website.

    Second, stating only that...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Cumulative count distinct for a period of 3 months

    Change your point of view.  Instead of looking back to see which customers were active, spread your customers' activities forward.  The following only takes one scan and one logical read.

  • This reply was modified 3 years, 11 months ago by drew.allen.

J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA

  • Reply To: Replace calendar table multiplier column with date logic

    Thanks for the improvement Jeff.  I was thinking about that after I posted and realized that it would limit it to just a year.  The mod that I was going...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Replace calendar table multiplier column with date logic

    This code produces the exact same results as Steve's but runs in about half the time.

    WITH BusinessDates AS
    (
    SELECT *, COALESCE(MAX(bd.BusinessDate) OVER(PARTITION BY MONTH(c.CalDate)...

    • This reply was modified 3 years, 11 months ago by drew.allen.

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: IIF statement query using SQL server

    I would use DATEADD() instead.   DATEDIFF() and DATEPART() use boundaries instead of full periods.

    WHERE wk.appl_createddate <= DATEADD(wk,4,wk.appl_conversiondate)
    AND wk.appl_conversiondate <= appl_createddate /* This may...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Joining large tables to small tables.

    satyanarayana09 wrote:

    Whenever you do a left join a small table and a large table make sure that large table is defined first in the join query. In your case the...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: SQL Query Question

    It looks like a packing interval problem.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Viewing 15 posts - 196 through 210 (of 4,085 total)