Forum Replies Created

Viewing 15 posts - 2,131 through 2,145 (of 2,462 total)

  • RE: Exclude rows

    Sean Lange (9/12/2013)


    select SUM(Case when MyType = 2 then -1 * MyHours else MyHours end) as TotalHours

    from #SomeTable

    If I understand the original OP correctly (" If something has been credited,...

    "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: Exclude rows

    Using the sample code above, I believe this will do the trick:

    WITH billed_credited AS

    (

    SELECT CaseNum, MyHours, COUNT(MyHours) AS bc

    FROM #SomeTable

    GROUP by CaseNum, MyHours

    )

    SELECT SUM(x.Myhours) TotalHours

    FROM #sometable st

    CROSS APPLY...

    "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: Exclude rows

    This is hard without DDL but assuming you cannot have this:

    Case | Hours | Type

    xxx | 3 | 1

    xxx | 3 | 1

    Or this:

    Case | Hours | Type

    xxx | 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: joining tables

    You should still be able to use UNION ALL in that scenario. Below is some code to create sample data similar to what I think you are dealing with. ...

    "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: What is the difference between sp_who2 and sp_whoisactive which one is better

    Ditto what Jack said.

    I always install sp_whoisactive and could not live without it (I run version 11.something). The most notable advantage over sp_who or sp_who2 is that you can...

    "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: joining tables

    Do you even need table1?

    I have this:

    Sample data (table1 included):

    USE tempdb

    GO

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

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

    CREATE TABLE table1

    (id int...

    "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: Index rebuild Maintenance Plan may not be running properly

    Any ideas on as to why the index rebuild task runs so quickly ?

    Either have a few really small indexes, a blazing fast server or not all the indexes are...

    "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: SSRS, how to logicaly combine related reports

    The short answer is: Yes, absolutely - there are several different ways.

    I have done this kind of thing many times but need to better understand your requirement 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

  • RE: Integration Services (BIDS)

    I'm assuming that "reversing columns and rows" you mean that the data needs to be pivoted.

    There are a few ways to do this. The SSIS Pivot Transformation task will work...

    "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: dynamic sql query?/

    Erland's article, "The Curse and Blessings of Dynamic SQL" (the link that OTF inlcuded) is the best I have ever read about DSQL.

    Itzek Ben Gan's Microsoft® SQL Server 2012...

    "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: Query help

    It seams to be working correctly for me as well...

    "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: subtract mutlple rows from top row value

    I took what Sean put together and added a little more sample data (a second order number) and changed it up a little. If I am correct you need 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

  • RE: subtract mutlple rows from top row value

    Based on what I think you may be looking for I came up with:

    WITH ddl_next_time_please(order_number, location, stop_type, stop_datetime, col) AS

    (SELECT 1303927,'Whouse1 PUP',4394903,'2013-08-11 07:26:33.000',1UNION ALL

    SELECT 1303927,'Store1 DRP',4394904,'2013-08-11 08:31:46.000', 2UNION ALL

    SELECT...

    "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: Cross Apply in Sql

    I also love Paul's articles on APPLY and would second that suggestion. If you own or have access to Microsoft SQL Server 2012 High-Performance T-SQL functions by Itzek Ben-Gen there...

    "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: How to Split String

    Sean Lange (8/29/2013)


    Alan.B (8/29/2013)


    The correct way to split a string using T-SQL would be to use Jeff's splitter as Louis mentioned. That said, what you are doing is quite simple;...

    "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 - 2,131 through 2,145 (of 2,462 total)