Forum Replies Created

Viewing 15 posts - 2,671 through 2,685 (of 7,619 total)

  • Reply To: NOOB question with Case statement

    case

    when columnA <> 0

    then columnB = 1

    else columnB

    end

    The main thing to understand about CASE is that every result from a CASE must be a single value.  The expression leading to...

    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 rollback transaction explicitly

    Certain errors by default won't fail the entire transaction/batch.  Before the transaction, use:

    SET XACT_ABORT ON

    to make SQL fail the entire transaction if an error like that occurs.

     

    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: Execution Plan vs Statistics I/0?

    I think we may have interpreted the q differently.  I took "statistics i/o" to mean the results from:

    SET STATISTICS IO ON;

    The logical i/o results are directly comparable, aren't they?

    I think maybe...

    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: Execution Plan vs Statistics I/0?

    Really it's best to use them in combination.

    High I/O numbers tell you to look for better ways to do related part(s) of a query.  The execution plan shows you what...

    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: Question on triggers

    Something along these lines:

    ALTER TRIGGER [dbo].[trig_UpdatePlacementCount]
    ON [dbo].[DebtorHistory]
    AFTER INSERT, UPDATE
    AS
    BEGIN
    SET NOCOUNT ON;

    UPDATE DI
    SET placement_count = dh.file_no_count
    FROM dbo.DebtorInfo DI
    INNER JOIN inserted i ON i.file_no = DI.file_no
    INNER JOIN (
    ...

    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: Is it possible to compare columns' content?

    You could do comparisons after the fact using the auditing data, but that would be big overhead.

    You don't need separate triggers for the original trigger to indicate which column(s) were...

    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: get around invalid date

    The problem with the all digits string is it can be mistaken for an integer.

    100% false.  Date literals are strings, or delimited in some other way to distinguish them from...

    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: Using SELECT LEFT and WHERE IN in the same SELECT Statement.

    This might give better performance, if the optimizer recognizes the chance:

    WHERE AKey LIKE '[ABCDEGJ]%' AND (AKey LIKE 'AAA%' OR AKey LIKE 'BBB%' OR AKey LIKE 'CCC%' OR...

    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: get around invalid date

    And if my suggestions are broken, are so bad, why do the recent DATE and DATETIME2(n) data types default to it?

    Default to what exactly?  We know they're not stored in...

    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: Index Theories on adding new columns (Not Nullable)

    I disagree; when at all possible, you want to make the clustered index unique yourself whenever possible.  Yes, SQL will always force it to be unique anyway, but that often...

    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: Greater-Than Empty String Comparison Yielding Unexpected Results

    I'd say just use > CHAR(0) if you're going to go that route.  Btw, wouldn't you have to use >= CHAR(9), just in case only a tab char was there?

     

    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: Using SELECT LEFT and WHERE IN in the same SELECT Statement.

    And that's why I wrote the code the way I did.  The other way is somewhat easier to code, but potentially far worse in performance.

    The underlying rule is:

    Never use 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: get around invalid date

    2) these display strings sort correctly in temporal order. They are not ambiguous.

    As I stated, In the real world dates are sometimes given as YYYY-DD-MM for certain regions of the...

    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: get around invalid date

    Actually, the format YYYYMMDD is perfectly acceptable under ISO.  I don't know why Celko insists on repeating his false claim over and over about YYYY-MM-DD despite being told that it'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".

  • Reply To: Using SELECT LEFT and WHERE IN in the same SELECT Statement.

    You probably need something like this:

    WHERE (AKey LIKE 'AAA%' OR AKey LIKE 'BBB%' OR AKey LIKE 'CCC%' OR AKey LIKE 'DDD%' OR
    AKey LIKE...

    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 - 2,671 through 2,685 (of 7,619 total)