Forum Replies Created

Viewing 15 posts - 691 through 705 (of 7,619 total)

  • Reply To: correct placement of comment block

    Put comments inside the code, not before it.

    frederico_fonseca stated why:

    (1) it's a royal pain trying to make automated changes if comments precede the CREATE / ALTER

    (2) it's odd to consider code...

    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".

  • Reply To: Query Table without index

    It sounds like maybe you need to make this adjustment to the code?:

    ...

    WHERE g.Year = @year and g.Month = @month AND g.FailureCount <> 0

    ...

    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".

  • Reply To: Cannot set a value when initializing a variable

    Are you exec'ing the code from a different db with a lower compatibility?

    This really looks like a compatibility issue.  Check the compatibility level of all dbs on that instance.

    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".

  • Reply To: Query Table without index

    There are some that are a negative number

    That seems logical, if it went from 1 to 0, the change would be -1.

    display the Largest positive number first.

    Could you explain this...

    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".

  • Reply To: Query Table without index

    If I understand the problem correctly, I think all you need is a standard LAG.  You may need to adjust the PARTITIONing columns and/or the ORDER BY:

    DECLARE...

    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".

  • Reply To: Ascending Order Issue in SQL

    If you can get rid of the DISTINCT, you can do as below.  If not, let me know and I will adjust code to work around the DISTINCT.

    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".

  • Reply To: Reconcile employees with multiple IDs into Unique IDs

     

    SELECT
    MIN(Emp_code) + CASE WHEN COUNT(*) > 1 THEN '_' + MAX(Emp_code) ELSE '' END AS Emp_code,
    MAX(Employee_Name) AS Employee_Name,
    ...

    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".

  • Reply To: Testing each row against multiple WHERE clauses and update

    Put the conditions in a separate table.  Then use a JOIN to UPDATE the original table based on the matching condition, or the first matching condition if multiple conditions could...

    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".

  • Reply To: backup and storage questions

    I recommend using another db -- let's call it the "history_db" -- to hold the prior months' data.  As each month passes, you move its table to the history_db.  Also,...

    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".

  • Reply To: Substitute 0 and 1 values in 1 column

    To flip 0/1 and vice versa:

    UPDATE dbo.table_name SET column = ABS(column - 1)

    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".

  • Reply To: Truncate partition table failed due to index not partition. Help please.

    frederico_fonseca wrote:

    ScottPletcher wrote:

    Create a unique clustered index on ( TNR_DATE, GSN_ID ).  You can still have a nonclustered PK on GSN_ID alone.

    and how will the OP create a non clustered...

    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".

  • Reply To: Truncate partition table failed due to index not partition. Help please.

    Create a unique clustered index on ( TNR_DATE, GSN_ID ).  You can still have a nonclustered PK on GSN_ID alone.

    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".

  • Reply To: Stored procedure able to be built over table that doesn't exist

    If you prefer, just point the old name to the new table; you can, and definitely should, still continue to clean up the old name after that, but it should...

    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".

  • Reply To: DB Mail sysmail keeps stopping. sysmail_start_sp takes forever and never finshes

     

    DECLARE @email_min_date_to_keep datetime;

    /* only delete email older than 7 days; change the -7 to whatever number of days you prefer before running */

    SET @email_min_date_to_keep = DATEADD(DAY, -7, CAST(GETDATE() AS date))

    EXEC...

    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".

  • Reply To: DB Mail sysmail keeps stopping. sysmail_start_sp takes forever and never finshes

    Review sysmail_event_log to get additional info on the error(s) that occurred in mail.

    Sometimes you also want to look at sysmail_faileditems but that likely won't be helpful for the type of...

    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 - 691 through 705 (of 7,619 total)