Forum Replies Created

Viewing 15 posts - 4,096 through 4,110 (of 7,615 total)

  • RE: Bones of SQL - Practical Calendar Queries

    whenriksen (10/13/2016)


    Another benefit to using the calendar table rather than the Select DateAdd, performance is much better when used for filtering/grouping.

    One request I received at my work was to see...

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

  • RE: Difference between purchase dates in days

    Do you want each individual date difference or do you just want an average days' difference between orders? The latter is much less work to calc :-).

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

  • RE: Bones of SQL - Practical Calendar Queries

    Good article, but there's a much easier way to calc the nth given day of a given month. Also, btw, Thanksgiving is the fourth Thursday of the month not...

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

  • RE: Synch 2 tables; performance

    Is SQL Replication available to you?

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

  • RE: Using SP in UDF

    Alaster07 (10/12/2016)

    Is there an alternative to what I am trying to do?

    Not really. Keep in mind that a function must consistently return the same value for the same input...

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

  • RE: insert into table with foreign key constraint

    What you're asking to do really isn't logical. Walk through this.

    You're telling SQL, with the FK: "Do not let me add a row to this table unless a matching...

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

  • RE: sp_msforeachdb DBCC SHRINKFILE Query Problems

    No need to shrink below a certain minimum size, even if you can. I've used 1GB below, but adjust it as needed for your environment.

    EXEC sp_MSforeachdb '

    IF ''?'' 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".

  • RE: amending a column to increment while inserting; then switching back

    The IDENTITY property can't be added to an existing column nor removed from a column.

    You could add an identity column to the table, if it doesn't have one, and then...

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

  • RE: Extract a uniform pattern from a file path

    As long as the file name is the only YYYYMMDDHHMMSS string in the file, I think you can just check for that pattern:

    SELECT input, SUBSTRING(input, PATINDEX('%[2][01][0-9][0-9][01][0-9][012][0-9][0-5][0-9][0-5][0-9]%', input), 14) AS extract

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

  • RE: Inaccurate executeion_count(s) in dm_exec_procedure_stats

    I assume you mean "sys.dm_exec_procedure_stats" although you never really stated that.

    I suspect it has something to do with SSRS. Maybe the proc is being called from the SSRS web...

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

  • RE: Getting the username of the user from the program into a audittrail

    Prior to updating the table, put the username in a known place, and the trigger can retrieve it from there and use 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".

  • RE: t-sql 2012 trigger

    Sean Lange (10/6/2016)


    ScottPletcher (10/5/2016)


    Sean Lange (10/5/2016)


    Thom A (10/5/2016)


    Sean Lange (10/5/2016)


    Be careful if you use this code as a starting point. It has scalar values being populated from the inserted table....

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

  • RE: Update Trigger

    Just in case you want to touch it up a bit:

    CREATE Trigger [dbo].[Test_UpdateTrigger_1]

    ON [dbo].[Department]

    AFTER UPDATE

    AS

    SET NOCOUNT ON;

    IF UPDATE(Department)

    BEGIN

    INSERT into Department_Audit (

    ...

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

  • RE: t-sql 2012 trigger

    John Mitchell-245523 (10/6/2016)


    Or create a unique filtered index to avoid the need for a trigger:CREATE UNIQUE INDEX UQ_CustomStudent_personID_value_attributeID

    ON dbo.CustomStudent (personID,value,attributeID)

    WHERE value = '17'

    AND attributeID = '9875'

    John

    I didn't go that route...

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

  • RE: t-sql 2012 trigger

    I interpreted the OP's requirement differently, i.e., a given personID cannot have more than one row with a value of '17' and an attributeID of '9875'. If so, then...

    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 - 4,096 through 4,110 (of 7,615 total)