Forum Replies Created

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

  • Reply To: how to return the min value of a column if a sub-query returns no results

    Jonathan AC Roberts wrote:

    drew.allen wrote:

    This gives the exact same results as Jonathan's but only reads the near and next term data tables once each.

    SELECT FP.UNDERLYING_SYMBOL,
    ...

    • This reply was modified 2 years, 1 months ago by drew.allen.

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Query help please

    The problem with your question, is that you've not given enough data to rule out potential incorrect queries.  For example, SELECT * FROM dbo.history returns the correct results for your...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Help with reading from JSON array

    You need multiple OPENJSON functions.

    select j.WorkId, r.[Busket Rule], r.Exit_Window, r.Startegy, r.Start_Date
    from openjson(@json)
    with (
    WorkId int '$.WorkId',
    OverrideRules NVARCHAR(MAX) '$.UpdateAttributes.OverrideRules' AS JSON
    ) j
    CROSS APPLY OPENJSON(j.OverrideRules)
    WITH (
    [Busket Rule] varchar(200) '$."Busket Rule"',
    Exit_Window...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: how to return the min value of a column if a sub-query returns no results

    This gives the exact same results as Jonathan's but only reads the near and next term data tables once each.

    SELECT FP.UNDERLYING_SYMBOL,
    ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: how to return the min value of a column if a sub-query returns no results

    One more thing.  There is no reason to use an explicit CAST here, and using an implicit CAST makes it much easier to read.

    /* Explicit CAST ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: how to return the min value of a column if a sub-query returns no results

    Please clean up your code before posting.  There are several issues with the code for your test data.

    1. You used PERMANENT tables rather than TEMP tables.

      1. The easier you make...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Help for "complex" group by Query

    The problem is that you haven't defined "total up" and "total down".

    Is it a change on the field "up"?  If so, your data is incomplete.  A value can be up,...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: How Can I set the right value according to comparison conditition

    This query produces the exact same results as your query with far fewer reads.

    WITH Order_Statuses AS
    (
    SELECT h.order_number
    , h.order_date
    , q.[label]
    , q.orderstatus_src
    , q.orderstatus_tgt
    , h.order_status
    ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Calculate the number of months for overlapping dates in data set

    For future reference, many people are wary of opening random files from the Internet.  If you want help, please post a script to create a TEMP table and insert the...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Task solution help request

    You can't generally define aliases INSIDE expressions.

    Drew

    PS: You're dates don't match.

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Return

    Jonathan AC Roberts wrote:

    Yes, that's a bit shorter and generally more efficient. I'm wondering if there were a lot more that 12 items per customer and the right indexes on the table...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Return

    Jonathan AC Roberts wrote:

    ;WITH CTE AS
    (
    SELECT DISTINCT CustomerCode
    FROM myTable
    )
    SELECT B.*
    FROM CTE A
    CROSS APPLY(SELECT TOP(12) *
    ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Last value in a row containing..

    Nested CASE expressions are very hard to read, because it quickly becomes difficult to tell exactly where you are in the nesting.  Here is an example that uses a single...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Need help with the query

    00000 is an integer, so you are explicitly converting your value to char, but then implicitly converting it back to integer when you add it to 00000.  You want to...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Lead Updates Not Working, Only Rendering Nulls

    Ken McKelvey wrote:

    Zososql wrote:

    update #leadtest set [gamedate] = (select Lead([gamedate], 1) OVER( ORDER BY [gamedate] ASC))

    LEAD is a windowed function - what makes you think it is going to...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

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