Forum Replies Created

Viewing 15 posts - 31 through 45 (of 7,612 total)

  • Reply To: Replace calculation in cursor with set based logic

    A quirky update seems to work, although that requires adding a Calculation column to the original table and making sure the original table is clustered by PricingDate, viz:

    CREATE TABLE #Test...

    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: t-SQL help..

    I think you might have to read the table again to do what you need to do.  Probably best to just do an INNER JOIN, though:

    select  t2.ID, t2.LINEX, t1.*

    from #tmp1...

    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: String or Binary Truncation Error Strange Behavior (SQL 2019)

    Create a temporary table to load into, with len of 5+, and see if any rows with data longer than 3 bytes are actually getting loaded.

    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: Fax/Phone Area code Substring

    Because you used a numeric data type (1) rather than a string.  Do this instead:

    ...
    )
    SELECT
    country_code,order_phone,
    case
    when country_code IN ('US','CA') and len(order_phone) = 10 then '1' --<<--
    when...

    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: Server Role for User Database Access

    Add that user to the "model" db -- with whatever permissions you want -- and they will automatically be added to every new db.

    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: Eliminate a function by writing out the code is now throwing an error

    SELECT TOP (1) reg
    FROM ( VALUES(@var1), (@var2) ) AS datetimes(reg)
    ORDER BY reg DESC

    This approach will be really useful if you ever have to add a 3rd (4th,...

    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 all databases on one server instance to find a specific view

    DROP TABLE IF EXISTS #view_names;
    CREATE TABLE #view_names (
    view_name nvarchar(100) PRIMARY KEY
    );
    INSERT INTO #view_names
    VALUES('>--->YOUR_VIEW_NAME_TO_SEARCH_FOR_GOES_HERE<---<')
    /*, ('another_view_name_could_go_here') ... */

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

  • Reply To: cte using POWER and Numbers table causes arithmetic overflow

    Exact code works for me in SQL 2022.

    Maybe use bigint rather than int!?:

    declare @status as bigint=83457678; 
    ;with nums(num, [2power_Num], bitcheck)
    as
    (
    SELECT Num, POWER(2, CAST(Num AS bigint)), (@status &...

    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: Deadlocks after index rebuild

    It's also possible that you were missing critical index(es) that were forcing full scans of the table.  Every issue is not necessarily always exactly the same as one that happened...

    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: Are the posted questions getting worse?

    Michael L John wrote:

    below86 wrote:

    Is there any circumstances where you would allow code with a  'SELECT * ' to go into production?

    I believe this should NEVER happen.  There is a discussion that...

    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 to show record in single row

    SELECT
    LEFT(Bname, CHARINDEX(' ', BName) - 1) AS BName,
    MAX(CASE WHEN BName LIKE '% Start%' THEN StartDate ELSE '' END) AS...

    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: How to convert run_date and run_time columns to datetime from SQL Agent systable

    I don't know of a super-slick way to do this off the top of my head:

    SELECT DISTINCT run_date, run_time, 
    CAST(CAST(run_date AS varchar(8)) +...

    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: Solution to a problem without using a CURSOR

    OOPS, SORRY, I did it back'ards.

    SELECT [Profile ID]

    FROM dbo.table_name

    GROUP BY [Profile ID]

    HAVING COUNT(DISTINCT [Customer ID]) =

    (SELECT COUNT(DISTINCT [Customer ID]) FROM dbo.table_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: Solution to a problem without using a CURSOR

    SELECT [Customer ID]

    FROM dbo.table_name

    GROUP BY [Customer ID]

    HAVING COUNT(DISTINCT [Profile ID]) = (SELECT COUNT(DISTINCT [Profile ID]) FROM dbo.table_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: Data Joining technique help

    You should definitely switch the key order on the lookup table, i.e., not:

    PRIMARY KEY CLUSTERED ( iid, cart_id )

    but instead do this:

    PRIMARY KEY CLUSTERED ( cart_id, iid )

    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 - 31 through 45 (of 7,612 total)