Forum Replies Created

Viewing 15 posts - 1,966 through 1,980 (of 2,462 total)

  • RE: Can you use Lag to avoid recursive CTEs?

    First, I do believe you can do this with using LAG. I don't have access to a 2012 instance at the moment; otherwise I could post an example.

    That said,...

    "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

  • RE: Stairway to SQLCLR Level 2: Sample Stored Procedure and Function

    SQLRNNR (2/19/2014)


    Great article. Very useful information.

    One question I think could be answered and would be very useful to those noobs to CLR.

    How do you get the varbinary representation 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

  • RE: Stairway to SQLCLR Level 2: Sample Stored Procedure and Function

    5 stars! I just finished this and really enjoyed it. This is turning into a very excellent stairway Solomon and I can't wait to read the rest of the "levels"....

    "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

  • RE: T-SQL Pivot Question

    Luis Cazares (2/7/2014)


    ...you're cheating with your test. You didn't clean up the buffer after the cross tabs and before the pivot. At least not in the code you posted. That...

    "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

  • RE: dense_rank

    Dwain Camps wrote this great article about this recently which was consistent with my experience using windows functions: The Performance of the T-SQL Window Functions[/url]. I suggest giving it a...

    "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

  • RE: Storing XML File

    This should get you what you need. Note my comments...

    -- global temp table can be accessed from inside a string

    IF OBJECT_ID('tempdb..##xmlTemp') IS NOT NULL DROP TABLE ##xmlTemp;

    GO

    --declare @xml nvarchar(max)-- You...

    "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

  • RE: get list of last non null values

    Nevyn (2/10/2014)


    I also tweaked to Nevyn's solution so that it will produce the correct answer (Nevyn's solution is very good but I think it should include WHERE rownum=1.)

    Yep. Was trying...

    "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

  • RE: get list of last non null values

    Had a few minutes to kill... Here's a solution using what is commonly referred to as the "Quirky Update". I included the code to make sample data...

    USE tempdb

    GO

    IF OBJECT_ID('tempdb.dbo.dimdate')...

    "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

  • RE: get list of last non null values

    First, Cudo's to Google Chrome. I just started typing this, then lost power. When I rebooted and opened Chrome my comment was still here.:w00t:

    Below is a better way to create...

    "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

  • RE: T-SQL Pivot Question

    Luis. Thanks for putting all this together; I wanted to reply soon but it's been a busy couple days.

    I have been playing around with the code you posted and...

    "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

  • RE: T-SQL Pivot Question

    Luis Cazares (2/4/2014)


    ... Why wouldn't you want to use a nice pre-aggregated cross tab approach?

    SELECT

    SUM(CASE qtr WHEN 1 THEN sales END) AS q1,

    SUM(CASE qtr WHEN 2 THEN sales END) AS...

    "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

  • RE: T-SQL Pivot Question

    Luis Cazares (2/4/2014)


    Hi Alan,

    You need to change your table to a subquery involving only the grouping columns and the ones to be aggregated.

    SELECT [1] AS q1, [2] AS q2, [3]...

    "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

  • RE: Need case expression for sql select statement

    Ditto what Sean said. There's many people who want to help but we just can't based on what you have provided thus far.

    That said, I am going to take...

    "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

  • RE: Using the informations in the database ReportServer

    twin.devil (2/4/2014)


    this link will be helpful for you to get info of ReportServer database

    http://sornanara.blogspot.com/search/label/Query%20ReportServer%20Database%20Tables

    .

    hope it helps

    This is a great blog post/series! I don't know if this helps the OP...

    "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

  • RE: SQL case when statement( without hardcode values)

    Sowbhari (2/4/2014)


    This might not be the most elegant way but give it a try

    SELECT StartDate =

    CASE WHEN CONVERT(VARCHAR(8),@Trandate,112)

    BETWEEN CONVERT(VARCHAR,YEAR(@Trandate)) + '0406'

    AND CONVERT(VARCHAR,YEAR(@Trandate)+1) + '0405'

    THEN CONVERT(DATETIME,CONVERT(VARCHAR,YEAR(@Trandate)) + '0406')

    WHEN CONVERT(VARCHAR(8),@Trandate,112)

    BETWEEN CONVERT(VARCHAR,YEAR(@Trandate)-1)...

    "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 - 1,966 through 1,980 (of 2,462 total)