Forum Replies Created

Viewing 15 posts - 16 through 30 (of 2,462 total)

  • Reply To: XML Parsing Problem

    Note that the "./" in your code is not required based on the XML Context. Also note that specifying that you need the elements' text, via text(), will improve performance.

    For...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: Cant cast VARCHAR(MAX) To XML Variable

    To better understand the problem and solution have a look at Well Formed XML:

     

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: Complex .Json Data Parsing with multiples Array elements into SQL (MS-SQL 2016)

    This is my first time messing with JSON in SQL. The BOL entry on this helped me.

    First, JSON is cases sensitive so, $.Data is not the same as $.data. Next,...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: Last day of the previous month - Format MM/DD/YYYY

    As Jeff mentioned, CONVERT + 101 gets you the formatting you need:

    SELECT CONVERT(VARCHAR(10), GETDATE(), 101);

    For the last day of the previous month:

    SELECT EOMONTH(DATEADD(MONTH,-1,GETDATE()));

    For the...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: Convert teradata REGEXP_INSTR into SQL SERVER

    You can create your own INSTR function leveraging ngrams8k.

    CREATE OR ALTER FUNCTION dbo.Instr8K
    (
    @string VARCHAR(8000),
    @search VARCHAR(100),
    @instance INT
    )
    /*
    Created by...
    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: Can anyone explain the design decision here?

    For cleaner code you can leverage fnTally. Since fnTally leverages TOP, you can exploit row goals as Steve Collins mentioned above.

    CREATE OR ALTER FUNCTION dbo.getYears(@year...
    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: Search Report definitions

    I don't have a server handy at the moment but what you are looking for is in the REPORTSERVER.DBO.CATALOG

    This has the RDL XML (Report Definitions) which you can query. To...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: Tally OH! An Improved SQL 8K “CSV Splitter” Function

    @ Alan,

    I'm honestly a little bit surprised that you're justifying a sort because it has a low row count.  We know how that usually works out.

    I was a little rushed...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: Tally OH! An Improved SQL 8K “CSV Splitter” Function

    apart from the performance that is likely to be quite bad has errors on its construct

    The Construct is a problem but I suspect the performance should be fine, STRING_SPLIT is...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: Creating indexes on a very large table takes over 5 hours

    there is currently no way to incrementally populate the table.

    ...  a [Huge] fact table that gets regenerated nightly

    This is a design/process issue more than a technical one. I'll put my...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: Execution plan flips from "good" to "bad" at a certain threshold

    A couple things to consider. First, In SSMS 2019 the actual execution plan will show you how much time each portion of the query took. You don't need that here...

    • This reply was modified 5 years, 9 months ago by Alan Burstein. Reason: Added another option - dbo.many
    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: can't get Numbers from Name to prevent conversion failed ?

    Grab a copy of PatReplace8K and it should be easy to strip out what you need.

    SELECT 
    pa.*,
    Clean1 = CAST(ISNULL(pr.newString,0) AS FLOAT),
    ...
    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: Longest Common Substring in an ITVF

    @sgmunson

    What you posted is similar to my first version of this except that I use my ngrams function to generate the tally table. Here's a simplified version of...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: string compare again .. :)

    Jeff Moden wrote:

    Agreed.  I said similar in this post from above...

    I missed this.

    The difference is that I did the split using an indexed view. This way the split only happens once,...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Reply To: string compare again .. :)

    Jeff Moden wrote:

    Alan Burstein wrote:

    Just as a side note, depending on how often your columns are updated/modified, you can always split the string ahead of time using a permanent tally table like...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

Viewing 15 posts - 16 through 30 (of 2,462 total)