Forum Replies Created

Viewing 15 posts - 136 through 150 (of 1,228 total)

  • RE: New T-SQL Functions: How to modify an ORDER BY clause at run-time using a parameter

    You can use CASE in the OVER clause:

    OVER (ORDER BY CASE WHEN @var=1 THEN Orderno ELSE Invoiceno END)

    Edit: typing on fone on train


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Rewriting the Sql code

    GilaMonster (6/3/2015)


    What, other than the NOLOCK hints, is the problem?

    The OP is confused by the location of the ON clauses. Since there are only INNER joins, I don't think it...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Returned value of a stored prcedure

    douglas.allison1 (6/2/2015)


    Hi All,

    I am running a sproc we have developed and I am getting a -6 as a returned value does anyone know what that actually means.

    TIA

    Doug

    Only the developer who...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Baffled by Query

    This should be straightforward - fetch the top row from the customer table (ordered by LastUpdated) and any row from MessageTypeTrack which matches the filter criteria. I think the optimiser...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Certain Value In Where Clause Hangs Query For 5 Minutes

    If you look at nodes 15 and 16 the actual and expected rowcounts are very different. The plan doesn't appear to be a good fit for this costcentre as it...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Certain Value In Where Clause Hangs Query For 5 Minutes

    Rowcounts in the actual and estimated plans are very different - do you know anything about statistics updates in the database?


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Using APPLY to make your queries DRYer

    brad.pears (4/2/2015)


    I've never seen that particular SQL coding before and I will try to use that. I have seen tons of SP's and views here where I work with lots...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: How to quickly update/insert 3M records in a large table?

    George Wei (3/28/2015)


    Dear all,

    Our system runs a SQL Server 2012 DB, it has a table (table_a) which has over 10M records. Our system have to receive data file from previous...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Populate table with some gaps in between

    SELECT [Out] = t.n+h.n+d.n

    FROM (VALUES (1000),(2000),(3000),(4000),(5000),(6000),(7000),(8000),(9000)) t (n)

    CROSS JOIN (VALUES (100),(200),(300),(400),(500)) h (n)

    CROSS JOIN (VALUES (10),(20),(30),(40),(50)) d (n)

    ORDER BY [Out];

    WITH rs AS (SELECT * FROM (VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9)) d (n))

    SELECT [Out]...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: @@ServerName shows different value

    Servername\instancename


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Help in query

    Eirikur Eiriksson (2/18/2015)


    ChrisM@Work (2/18/2015)


    Here's another way:

    SELECT

    a.[Pax ID],

    a.[Flight Date],

    a.[Flight Number],

    [Last Mod Date] = CASE WHEN x.[Pax ID] IS NULL THEN a.[Last Mod Date] ELSE x.[Last Mod Date] END,

    [Status] = CASE...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Query Causing Blocking, Locks Table for 1000 Seconds, Help Needed!

    Velveeta22 (2/14/2015)


    I have updated the data set and DECLARE variables in my posts. Thank you for those tweaks!

    You're welcome - and thanks for the updates. I won't get near...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Query Causing Blocking, Locks Table for 1000 Seconds, Help Needed!

    Velveeta22 (2/13/2015)


    This will install a sample db, tables and some objects. I put around 20 rows of anonymized data in each table:

    ...[/code]

    Thanks for this - there are a few...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Query Causing Blocking, Locks Table for 1000 Seconds, Help Needed!

    Velveeta22 (2/13/2015)


    Not the CROSS APPLY, but the CROSS JOIN in [t4].

    That's the one. The WHERE clause at the end of all the queries turns it into an inner join. You...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Query Causing Blocking, Locks Table for 1000 Seconds, Help Needed!

    Velveeta22 (2/13/2015)


    There are 92k rows in the OutBoxData table. Is this query processing 92k rows x each OutBoxAN by using the CROSS JOIN?

    I took the SELECT query that creates...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

Viewing 15 posts - 136 through 150 (of 1,228 total)