Forum Replies Created

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

  • Reply To: More XML Query Magic Required

    I'm not sure if this is more efficient, but this also works.

    SELECT PackageName = 'Project'
    ,ItemType = 'Project Parameter'
    ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Grand Total

    This sounds like something that should be done in the presentation layer, not the data layer.  This is easy in SSRS, for example.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Date filtering using DATEDIFF

    You have your dates switched in the DATEDIFF function.  It should be DATEDIFF(DAY, LAG(...), visit_date_01).  Or you should be using LEAD() instead of LAG().

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Convert from nvarchar to numeric only if valid number-VAL command like MS Access

    Use the TRY_CONVERT() or the TRY_CAST() function.  They will return the value if it can convert/cast it, and will return NULL otherwise.

    Drew

    • This reply was modified 6 years ago by drew.allen.

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: ORDER BY in the OVER clause

    Certain windowed functions that use an ORDER BY clause require a frame.  If you do not provide a frame it uses the default RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW. ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: create new table from two others but have consistent date ranges

    First, most people are hesitant to open attached files from random strangers on the net.  You should provide scripts using the {;} Insert/edit code sample button just above the text...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Number generation based on 3 columns

    And why does the col2 value switch from ab to dd on 08/04/2020?

    It looks like you want a DENSE_RANK(), but the exact details depend on your answer to Phil`s question.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Query Help - History Table with no range data.

    Based on Neil's sample data, here is a first attempt at a query.

    SELECT c.Name, c.NameKey, c.SaleDate, c.SaleQuantity, c.CurrentCategory, h.Value
    FROM #Current c
    OUTER APPLY
    (
    SELECT TOP(1) *
    FROM #History h
    WHERE h.NameKey...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Compare data for 4 columns

    You've been around long enough to know that you should provide sample data and expected results.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Query Help - History Table with no range data.

    A picture of your data is worthless.  You need to supply actual data by supplying a script using the {;} Insert/edit code sample to do the following.

    • Create a temp...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Trying to insert data from one table to another

    We don't have enough information to tell you exactly what the problem is, but the error message gives you a LOT of information.

    1. Your table dbo.ItemDetail has a primary key...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Merge statement - matching ON all columns

    Phil Parkin wrote:

    If there are no updates (impossible without a key) or deletes, I would suggest not using MERGE, but INSERT:

    INSERT target (cols)
    SELECT cols FROM source
    WHERE NOT EXISTS...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: need help parsing xml

    Please do not cross post.  Please respond on this thread https://www.sqlservercentral.com/forums/topic/need-help-parsing-xml-3#post-3727725

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: need help Parsing XML

    Sometimes a backslash is used to insert a literal character.  It looks like whatever produced this XML hypercorrected and used \" to insert a literal double quote (") when it...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: math issue

    The issue that you're running into is that the two separate queries have different criteria and you aren't taking that into account when you are combining them into one query. ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

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