Forum Replies Created

Viewing 15 posts - 3,151 through 3,165 (of 7,619 total)

  • RE: Query: Get Top 3 Records for multiple Field categories


    SELECT EName, UnitsSold, Category
    FROM (
        SELECT *, ROW_NUMBER() OVER(PARTITION BY Category ORDER BY UnitsSold DESC) AS row_num
        FROM #t
        WHERE...

    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: Change Logs

    You should do at least some normalization here.  I'd say the below is the minimum.  Easiest is a separate row for each column.  Without more normalization, yes, that will result...

    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: UK Date Error - SQL2008

    You could change the date format just for that code:


    DECLARE @dateformat_setting char(3)
    IF OBJECT_ID('tempdb.dbo.#useroptions') IS NOT NULL
      DROP TABLE #useroptions
    CREATE TABLE #useroptions (

    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: Compare Table Contents Procedure

    DinoRS - Tuesday, October 2, 2018 5:55 AM

    francesco.mantovani - Thursday, September 20, 2018 3:17 PM

    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 can we auto increment by 1 from the max ID with an update or an insert into to the same table.

    Sorry, extremely busy at work, didn't finish code before.  Maybe as below?


    INSERT INTO [dbo].[SomeCause] ( SomeID, SomeType, SomeThingElseID, SomeDesc )
    SELECT SC.SomeID, SC.SomeType, SC.SomeThingElseID_New, SC.SomeDesc

    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: Format column as HHH:MM:SS instead of MMM DD YYYY HH:MM (AM/PM)

    If those values truly correspond with your results:
    741:51:59 = Jan 30 1900 11:34PM
    then I'm not sure what you can, as I don't see a clear link between the two...

    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 can we auto increment by 1 from the max ID with an update or an insert into to the same table.

    You didn't provide enough data to know that you want to INSERT, but you likely want something along these lines:


    INSERT INTO [dbo].[SomeCause] ( SomeID, SomeType,...

    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: error concatenating parameter inside exec


    exec('declare @testvar nvarchar(128); select top (1) @testvar = NameSchema from #TempCommonMatchFormatted; select @testvar as testvar')

    If you want to return a value(s) 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: Looking for advice on error logging.

    The code looks good to me.  I think it's better to test row existence outside the TRY.

    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: Where would you use XACT_STATE

    You use XACT_STATE() to:
    (1) avoid attempting a ROLLBACK or COMMIT when a trans is not active
    (2) to know whether to do a ROLLBACK or COMMIT in certain cases (if...

    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: Select Number of Times a Product sold per minute

    I can't tell specifically what you need, but I suggest using the "standard" approach to adjust a datetime to a given boundary.  For example, the code below totals by MINUTE,...

    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: Table Joining

    As to the query plans for these:

    SELECT A.FirstName, A.LastName, B.Location
    FROM TableA A
    LEFT OUTER JOIN TableB B
    ON A.PersonId = B.PersonId AND B.Location = 'London'

    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: move sql database files to bigger drive

    my question - once sql is restarted all databases will come back online using same drive letter path? correct? 

    Yes, the E:\ paths will be the same, if...

    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: Compare Table Contents Procedure

    You should also look at tablediff.exe to do that. 

    Yeah, being a command-line utility it's a little quirky to get used to, but I've found it works well...

    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: bcp with Quote Text Qualifier and Comma Delimiter

    Use:
    -t ","

    instead of:
    -t "|"

    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 - 3,151 through 3,165 (of 7,619 total)