Forum Replies Created

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

  • Reply To: Remove ISNULL FROM left join to make SARGAble

    It looks like you are using a NULL value to represent an unknown/unspecified date.  While you may not be able to change this, it's better to use a specific unlikely...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Merge spans with Dates Logic

    Another thing I should point out is that Johan's code assumes that your data is "clean", that is, that there are no overlaps.  Mine will handle overlaps.  An easy way...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Merge spans with Dates Logic

    Here is a different approach based on an article by Itzik Ben-Gan.

    There are three types of intervals that you can work with:

    • Open intervals -- Neither endpoint is included
    • Half-closed...

    • This reply was modified 1 years ago by drew.allen. Reason: Comment about the SUM being zero or NULL was on the wrong line
    • This reply was modified 1 years ago by drew.allen.

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: temp table columns not showing up in CTE

    pietlinden wrote:

    When you define your CTE, you have to specify the column names...

    WITH cteExample (FirstName, LastName, IDNo)
    AS
    (
    SELECT fName, LName, NotMySSN
    FROM tableX
    )
    SELECT FirstName, LastName
    FROM cteExample
    WHERE IDNo > 10;

    If...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: temp table columns not showing up in CTE

    Your final select in that statement is

    select contractnumber from d group by contractnumber having count(*)>1

    Those added columns do not appear in that SELECT, so they do not...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Cummulative Total

    jagjitsingh wrote:

    Error - Windowed functions cannot be used in the context of another windowed function or aggregate.

    SELECT ROW_NUMBER() OVER (PARTITION BY Account ORDER BY A."Account") AS "RowNo", A."Account" AS "Account", (A."Debit")...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Why I get null instead I should get 0

    Do you really need to create 12 temporary tables to demonstrate the problem?

    Also, you should use the {;} Code button to format your code.  It makes it much easier to...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Prepare Sum of Bill Amount Having two different status with fast performance

    Photos of data are not data.  If it's not worth your time to provide actual data, it's not worth my time to scrape your photos for actual data.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Select statement with in using multiple columns

    I believe that this also works.  I have no idea which is more efficient.

    CREATE PROCEDURE ListNeedsResult

    @RecordID int

    AS

    SET NOCOUNT ON

    SELECT
    Sequence,
    Need
    FROM
    dbo.NeedsAssessment
    WHERE EXISTS
    (
    SELECT * from Assessments
    WHERE RecordID =...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Calculating Numerator and Denominator

    There is no way for us to help you with the minimal information that you have given.  There is likely a problem with your JOIN conditions resulting in too few/many...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Count of Total Appointments within 30 days of each Appointment Date

    Please don't cross post.  It tends to fragment the discussion.

    Please respond to this post https://www.sqlservercentral.com/forums/topic/count-of-total-appointments-within-30-days-of-each-appointment-date

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Sql script replace and rearrange numbers

    Steve Collins wrote:

    Sorry, sorry my apologies.  I didn't catch the inconsistency.  The green arrows in the image you posted only point up!  Afaik that's the part I missed.  Once there's an...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: identify consecutive records greater than 1

    Here is a slightly different approach.  There is no discernable difference in the performance for the sample data.  When I add a primary key on Number and StartTime, this approach...

    • This reply was modified 1 years, 5 months ago by drew.allen. Reason: Changed COUNT to SUM

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Combine Overlapping Date Ranges Per User

    Another thing.  In cases such as this, it's usually best to start a new post and reference the old post instead of hijacking the original post.  Otherwise it can get...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Combine Overlapping Date Ranges Per User

    The problem is that your data is stored as closed intervals (both end-points are included in the interval) when this issue requires half-closed intervals (only one end-point is included in...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

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