Forum Replies Created

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

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

  • Reply To: Performance on large table -Index Creation

    Drop the existing index.

    Assuming that the column is datetime and not just time, create a clustered index on the datetime column.

    It would be better to use datetime2 type to reduce...

    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: Purging / deleting ExternalMailQueue which has around 700,000 records

    Maybe try:

    EXEC msdb.dbo.sysmail_delete_mailitems_sp

     

    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: Import Agent job history from another server

    No problem.  Let me know if you need help on getting the correct job_id to add to the sysjobhistory table.

    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: Import Agent job history from another server

    You can't restore an older version msdb over another msdb anyway, no matter what.

    You could, however, restore the msdb db to a different db name (e.g. msdb_old).

    I think you 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: search index

    It doesn't.  You're wayyyy over-analyzing this.  Again, it's a simple q with a simple answer.  Save the big analysis for a more significant q.

    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 Help

    select T.*, T2.VAL

    from @T T

    outer apply (

    select top (1) t2.*

    from @T t2

    where t2.ID <= T.ID and

    t2.VAL is not null

    order by t2.ID desc

    ) as T2

    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,613 total)