Forum Replies Created

Viewing 15 posts - 4,111 through 4,125 (of 7,615 total)

  • RE: t-sql 2012 trigger

    Sean Lange (10/5/2016)


    Thom A (10/5/2016)


    Sean Lange (10/5/2016)


    Be careful if you use this code as a starting point. It has scalar values being populated from the inserted table. This is very...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: Monthly total of active data

    I assumed a physical tally table, column name "N" (ugh!, but most common I guess), to avoid having to use an inline CTE:

    DECLARE @start_date datetime

    DECLARE @end_date datetime

    SET @start_date = '20160101'

    SET...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: Add column value depending on other value in same row

    My best guess is something like this:

    UPDATE sc

    SET column_x = ISNULL(sot1.value, '') + ISNULL(sot2.value, '') + ISNULL(sot3.value, '')

    FROM dbo.SaltoCardholders sc

    LEFT OUTER JOIN dbo.some_other_table1 sot1 ON sot1.lookup_col = sc.loc

    LEFT OUTER JOIN...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: How to improve the efficiency of a conditional join

    The most important thing is to:

    Cluster the dbo.FreightRate table on ( SourceKey, CompanyKey, PackingType ).

    But you could adjust the query slightly also:

    SELECT COALESCE(fr1.FreightRate, fr2.FreightRate, fr3.FreightRate, 0)

    FROM dbo.Sales s

    LEFT JOIN dbo.FreightRate...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: Backup database only if changes happen

    To be fair, the number of databases would have an impact here. I've got servers with hundreds (and hundreds) of dbs. Even small files add up to a...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: How to use sp_msforeachdb to create multiple table in multiple databases

    drew.allen (10/4/2016)


    ScottPletcher (10/4/2016)


    Create a proc in the master db, beginning the name with "sp_", mark that proc as a system object, then use sp_MSforeachdb to run the proc in the...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: How to use sp_msforeachdb to create multiple table in multiple databases

    Create a proc in the master db, beginning the name with "sp_", mark that proc as a system object, then use sp_MSforeachdb to run the proc in the db(s) you...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: count every hour per day

    DECLARE @start_date datetime;

    DECLARE @end_date datetime;

    SET @start_date = '20010101';

    SET @end_date = '20010101 23:00';

    ;WITH tally10 AS (

    SELECT number FROM (VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0)) tally(number)

    ),

    tally1000 AS (

    SELECT ROW_NUMBER()...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: How to get the previous weeks data based on week ending

    Sorry, just now have time to follow up on this.

    CROSS APPLY (CA) really is a type of join, I'm just co-opting it here to assign names to values. You...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: How to get the previous weeks data based on week ending

    I think messing with DATEFIRST when you don't absolutely have to is just asking for issues later. The CROSS APPLYs are used just to simplify the main SELECT list...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: Execution Plan Help. Enormous Increase in row count in plan

    thomashohner (9/30/2016)


    The clustered index issue is hard as these are staging tables and the method we use from change tracking is prone to duplicate inserts sometimes. Its far from ideal....

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: Execution Plan Help. Enormous Increase in row count in plan

    thomashohner (9/30/2016)


    WOW, you have to be joking. 14 seconds row count on the money. Attached is the execution plan.

    Thank you both so very much. Holy molly :-D:-D

    Great, glad it...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: Execution Plan Help. Enormous Increase in row count in plan

    Try this:

    ...

    Ethnicity,

    MaritalStatus,

    ...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: Intentional Normalization Violation

    In this case, I think it's ok to add the current status to the Orders table, using an efficient, well-written trigger to maintain the status.

    However, the lookup of the current...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • RE: Execution Plan Help. Enormous Increase in row count in plan

    I can't see any of the indexes, but perhaps you can combine the Lists lookups as below.

    Also, you'll probably get best performance by clustering the Lists table by ( Databasekey,...

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

Viewing 15 posts - 4,111 through 4,125 (of 7,615 total)