Forum Replies Created

Viewing 15 posts - 2,866 through 2,880 (of 7,619 total)

  • Reply To: Best Practices for Stored Procedure Design

    I doubt you need a temp table. You can just UNION ALL all the different query results. If a given query returns no rows, that's OK, it will...

    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 compare three tables using a single column (inner Join is not working)

    Do you want to list inactive data in the report?

    If not, you can just join to the other tables including "AccountStatus IN (1)" in the JOIN ON clause, something 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".

  • Reply To: Split Row Into Multiple Based on Column Values

    Personally I'd use CROSS APPLY:

    SELECT sl.Name, sl.Country, types.type

    FROM Sales_Ledger sl

    CROSS APPLY ( VALUES([Type 1]), ([Type 2]), ([Type 3]), ([Type 4]) ) AS types(type)

    WHERE types.type > ''

    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: SELECT COUNT(*) Taking a Very Long Time

    Hopefully SQL's split algorithm isn't that poor for bit columns.

    But, if it turns out to be, create an index on:

    ( MyTable_ID, is_MyTable_Text_NULL ).

    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: SELECT COUNT(*) Taking a Very Long Time

    Add a bit column to indicate null status of [MyTable_Text], then index on that column.

    ALTER TABLE [dbo].[MyTable] ADD is_MyTable_Text_NULL AS CAST(CASE WHEN MyTable_Text IS NULL THEN 1 ELSE 0 END...

    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: Select column names and top 1 records along.

    You don't want index_columns and indexes in the query as it exists, because it will just generate duplicate rows for no reason.

    SELECT TOP (1)

    st.name [Table Name],

    c.name [Column Name],

    t.name [Data Type]

    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: building one group from other groups aggregated

    You need more clear examples.

    For example, if line 1 was the starting line, which of these lines would be included:

    0 200 0 0 501 --line 5

    200 0 0 0 0...

    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: INSERT INTO table if 4 or less occurrences of values exist in table

    That's a very interesting idea. It sounds very complex to implement, but quite nice once you get it working.

    The trigger is actually rather easy to write and can be...

    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: adding default column with type BIT and default value as Y

    Bit data type is numeric in SQL: naturally 1 means Yes, 0 means No.

    So:

    CREATE TABLE dbo.table_name ( bit_column bit DEFAULT 1 );

    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: Simple Index Question

    But you also made the blanket statement that:

    Indexes are for reducing the rows read, they have no value at all when you don’t have a where clause filtering the rows.

    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: Simple Index Question

    Not necessarily true. Indexes can also allow SQL to avoid a sort (and sorts are expensive operations).

    For example:

    Add a clustered index on id to the table.

    Then this query should...

    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: INSERT INTO table if 4 or less occurrences of values exist in table

    You'd have to use an INSERT trigger. It could be an INSTEAD OF INSERT or an AFTER INSERT trigger.

    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: Look at ROWCOUNT and ERROR just after update?

    Yep. Save the system variables (@@) into local variables (@) after the relevant statement(s), then test the local variables instead of the system vars. Note that you need...

    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: New to SQL, easy question

    I didn't, and wouldn't, look at the links. But thanks for the heads-up on this poster.

    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: The object name contains more than the maximum number of 2

    You can have the db name in an ALTER, just not the server name (note the message says two prefixes, i.e., a total of 3 levels of object 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".

Viewing 15 posts - 2,866 through 2,880 (of 7,619 total)