Forum Replies Created

Viewing 15 posts - 1,531 through 1,545 (of 7,613 total)

  • Reply To: Help with SUBSTRING CHARINDEX

    LTRIM(RTRIM(SUBSTRING(name, CHARINDEX(')', name) + 1, PATINDEX('%[+-][0-9]%', name) - (CHARINDEX(')', name) + 1))))

    ;WITH test_data AS (
    SELECT * FROM ( VALUES('(b) Joe Brown -12563'), ('(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".

  • Reply To: Maintenance Question

    It depends.  If there's a large volume of data written to your SQL log even when there are no errors, then you should probably switch the logs more often (and,...

    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: Help with writing SQL logic

    No directly usable data to test with, but I think this should at least be close:

    SELECT PH.*, PA.*
    FROM dbo.PolicyHeader PH
    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".

  • Reply To: Lock table for Insert/Update/delete

    Add WITH (TABLOCK) hint after the table name.

    Examples:

    UPDATE dbo.table_name WITH (TABLOCK)

    SET ...

    INSERT INTO dbo.table_name WITH (TABLOCK)

    SELECT ...

    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: SQL Subqueries

    I think you can combine the first two queries into a single query, also avoiding having to rank all the totals:

    WITH cteCombined AS
    (
    SELECT TOP (1) WITH...

    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: Speed up join

    For the much more straightforward approach:

    SELECT DISTINCT N

    vs

    SELECT N

    ...

    GROUP BY N

    my machine shows a slight edge for DISTINCT.  That's what I've seen in normal usage, too.  For a straight list...

    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: indexes: seeks and scans, what do the numbers mean?

    No, it's not a row total, as Steve noted.  It's the number of seek operations since the stats for that index were created.

    One query that reads, say 5,000 rows, might...

    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: SQL Server High CPU Usage - (I think it's been taken care of, lol)

    Well, good luck.  Since your posts seem to disagree with themselves, I don't think I can be of any more assistance.

    "we are getting emails of large queries taking longer 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".

  • Reply To: Tables are empty but catalog views show that they have rows

    Hmm, do you have tables under different schema names?  Is it possible that dbo.same_table_name is empty, but some_other_schema.same_table_name has rows?

    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: SQL Server High CPU Usage - (I think it's been taken care of, lol)

    What is the "cost threshold for parallelism" setting?  If it's lower than, say, 50, you should seriously consider changing it.

    Did you verify there are no physical issues -- controllers, NIC/communication...

    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: SQL SERVER CLUSTERING INTERVIEW QUESTIONS

    Jeff Moden wrote:

    rehvin wrote:

    Hi guys, I have found this resource for interview preparation https://artoftesting.com/sql-queries-for-interview

    Lordy... not another one... 🙁  Jumping straight to the final two questions in the "experienced" section...

    Without loading it...

    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: What to build the first time

    That's too much for a single q here.  You need to break this into separate qs, each with a single and specific 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: SQL Subqueries

    Your "first attempt" looks remarkably similar to the code I posted on an almost identical q of yours:

    https://www.sqlservercentral.com/forums/topic/printing-the-highest-count#post-3889964

    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: Printing the Highest count

    Nvm.

    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: Printing the Highest count

    You can use a subquery, but you don't technically need it.  If branches tie and you want to list all tied branches, change to "TOP (1) WITH TIES".

    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 - 1,531 through 1,545 (of 7,613 total)