Forum Replies Created

Viewing 15 posts - 2,851 through 2,865 (of 7,619 total)

  • Reply To: One-to-Many entity in a single table

    SELECT emailaddress, COUNT(DISTINCT emailID) AS emailID_Count
    FROM ##myTable
    GROUP BY emailaddress
    HAVING COUNT(DISTINCT emailID) > 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: Create Key with distinct values

    Table "C" only has each unique Name and EIN combination only 1 time, no matter how many fiscal years or amounts it has.  That't the whole point of the "C"...

    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: Create Key with distinct values

    You can use either VALUES or SELECT, you can't combine them:

    Insert into Cntrl.tbl_Entity_master

    select distinct [Entity Name], [Entity EIN] from B

    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: Create Key with distinct values

    Yep, just create another table.

    CREATE TABLE dbo.Entity_master (

    [Entity Name] nvarchar(60) NOT NULL, [Entity EIN] char(10) /*or whatever*/ NOT NULL,

    CONSTRAINT Entity_master__PK PRIMARY KEY ( [Entity Name], [Entity EIN] )

    )

     

     

    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: Good sources for SQL training?

    Itzik Ben-Gan books and/or videos.

    Books will typically you a much more in-depth knowledge.  If you'd rather just have an overview level of knowledge, then a video(s) would work.

    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: Estimated Number of Rows 4,056,100,000,000,000,000,000,000 !

    We really need to see the execution plan.  Estimated is probably good enough, although actual is better.

    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: Create Key with distinct values

    You need a separate table to specify a unique entry for ( [Entity Name], [Entity EIN] ).

    (Actually, hopefully EIN by itself would be unique.  If it is, use just 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: Learning SQL!!

    Which specific brand of SQL?  MySQL?  SQL Server?  Oracle (not likely in a 2-person shop, too expensive)?

    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: Stored Procedure for three different date ranges

    You can't pass expressions as parameter values.  You need to resolve the expression yourself and pass only a single (scalar) value.  For example:

    DECLARE @start_date date

    DECLARE @end_date date

    SET @start_date = DATEADD(MONTH,...

    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: Update trigger and concurrency issue

    I don't know that  you'll be able to fix it, particularly without the details of how the "standard audit dates" are maintained.

    It seems like this is an integrity check 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: Best Practices for Stored Procedure Design

    Right, good point.  I meant to do that.  You just do an INNER JOIN to the table of allowed values, with a WHERE clause(s) if needed .

    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: View triggers

    Quite right.  If you wanted to use a trigger, you'd have to put a trigger(s) on the table(s) used within the view, not on the view itself.

    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: Best Practices for Stored Procedure Design

    Sure.  Based on the originally posted query:

    SELECT @currentValue, SomeField
    FROM SomeTable
    WHERE @currentValue = 'Test1'
    UNION ALL
    --
    SELECT @currentValue, SomeField
    FROM AnotherTable
    WHERE @currentValue = 'Test2'
    UNION ALL
    --
    SELECT @currentValue, SomeField
    FROM AThirdTable
    WHERE @currentValue = 'Test3'
    UNION...

    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: Best Practices for Stored Procedure Design

    Yes, I should have said "and without a loop".

    For me, I'd use UNION ALL rather than a loop for something like this. SQL will have to parse all the SQL...

    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: Best Practices for Stored Procedure Design

    How would you pull data from at least 4 different tables efficiently without using a UNION ALL?

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