Forum Replies Created

Viewing 15 posts - 3,811 through 3,825 (of 7,613 total)

  • RE: Highest value supported by 2 of 3 columns

    The second-highest score should always give you the desired value:


    SELECT t.ID, t.Score1, t.Score2, t.Score3, ca1.FinalScore
    FROM #tmp t
    CROSS APPLY (
        SELECT TOP...

    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: Is my avoidance of UPDATE/DELETE CASCADE on foreign key relationships valid?

    If the tables are not too large, you could even consider using CASCADE only when deliberately making changes, i.e., drop the FK constraints, recreate them as CASCADE, change the name(s),...

    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 best approach

    Just UNION (not UNION ALL) the two tables:


    SELECT *
    FROM #temp1
    UNION
    SELECT *
    FROM #temp2
    ORDER BY <column_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".

  • RE: [Best Practice] VARCHAR >> INT and Truncation

    Luis Cazares - Wednesday, May 17, 2017 7:27 AM

    autoexcrement - Tuesday, May 16, 2017 4: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: (Quickly) Delete records from a table, with condition

    You can use your initial DELETE, perhaps looping it as well:

    DELETE TOP (50000) FROM WHERE DATE BETWEEN X AND Y;

    You'd be better off clustering...

    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: Help with joining to a table with "wildcard" data

    Try this:


    SELECT T.InvoiceNumber, T.EntryCode AS InvoiceEntryCode, T.StoreNumber AS InvoiceStoreNumber, T.RptLevel AS InvoiceRptType,
    OA1.*
    FROM #tmpTransactions T
       OUTER APPLY (
        SELECT TOP...

    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 convert string to "data type" ?

    You should look into using sql_variant data type, it could help you do this.  You'd have to use the desired data type, or cast to an explicit type, when loading...

    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: Dynamic SQL - Run formula in field

    For now, off the top of my head, I don't see any way to avoid a cursor. so that you can dynamically evaluate each expression using sp_executesql.  But other than...

    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: Drop/Create objects versus Alter

    And don't forget about extended properties.  Those would all be lost too if you DROP/CREATE.  As would of course any original "create_date".

    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: Querying Postcodes gracefully

    Thom A - Wednesday, May 3, 2017 4:39 PM

    ScottPletcher - Wednesday, May 3, 2017 4:05 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: Querying Postcodes gracefully

    Change your table to never store the space in the post code column (you can use a trigger to do this, at least until you change the app; you can...

    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: Find highest number in a column of strings

    If the format is always xxx###, then:
    SELECT MAX(RIGHT(column, 3))

    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: Federal Holiday Function

    Here's another alternative.  Btw, I corrected two holiday descriptions, for Jan and Feb.  It's not "President's Day", it's "[George] Washington's Birthday"; I wish the media would stop repeating the wrong...

    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: Query for status

    I think something along these lines:


    SELECT user,
      CASE WHEN confirmed_count = user_count THEN 'Confirmed'
       WHEN not_confirmed_count > 0 THEN 'Not Confirmed'
       WHEN confirmed_with_caveat_count >...

    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: database design

    Do a data design first -- that is, a logical design -- before you do a database design (a physical design).  Otherwise you almost always end up with a poor...

    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,811 through 3,825 (of 7,613 total)