Forum Replies Created

Viewing 15 posts - 3,631 through 3,645 (of 7,619 total)

  • RE: I have to get a count of orders placed between 1 pm yesterday and 1 pm today by day

    Here's one way:


    SELECT CAST(DATEADD(HOUR, 11, OrderDate) AS date) AS Date,
      COUNT(*) AS Count
    FROM (VALUES
     (908, '1/3/2018 13:20:34'),(
    909, '1/3/2018 15:18:41'),(
    910, '1/4/2018 09:15:21'),(

    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: Issue with ROW OVER partition


    SELECT {column_list, ...}
    INTO #TEMP2 -- Max ZATS
    from
    (
    Select
    ZBF.[HTS_NUMBER]
    ,#TEMP1.Part_Num
    ,row_number() OVER (PARTITION BY Composite_part ORDER BY Insert_Date DESC) AS Max_Date
    ,Max ([TSI].[ZATS_BROKER_FEED].Insert_Date) as...

    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: Adding indexed computed column to vendor system-any negative impacts?

    Create views to do the joins.  Yes, users shouldn't be expected to correctly write 5-column joins.  And they never should -- they should use a view that does the join(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".

  • RE: Convert from datetime to varchar to int


        , cast (convert(varchar(8), po.PolicyIssueDt, 112) as int) as PolicyIssueDt

        , cast(convert(varchar(8),po.PolicyEfftvDt, 112) as int) as PolicyEfftvDt

        , cast(convert(varchar(8), po.PolicyExpirDt, 112) as int) as PolicyExpirDt

    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: Composite Key Assistance

    You may or may not need to create another index for StoreNumber first.  It's possible SQL would never use such an index even if you created it.

    If 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: Merging user data

    If you have FK relationships, you don't have to do the data changes yourself.

    Script out the FKs, "DROP and CREATE", and change the "ON UPDATE CASCADE" to "ON...

    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: Trigger to avoid drop online database

    I don't know about detach at this point, but with some "fancy footwork" you can DROP a database only if it was OFFLINE.  You have to rollback the DROP, of...

    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: How to convert kilograms to pounds and ounces

    John Mitchell-245523 - Friday, December 29, 2017 8:23 AM

    ScottPletcher - Friday, December 29, 2017 8:18 AM

    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: How to convert kilograms to pounds and ounces

    Or perhaps multiply by 2.2046226218, or some shorter variant of that, if you need more accuracy.  2.2 is rather rough estimate.

    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 hardcoded database names in query when database names are different on development and production server

    Maybe easy, maybe not.  You have to create a synonym for every remote object you reference.  And keep them in sync if, for any reason, you have to rename an object.

    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 hardcoded database names in query when database names are different on development and production server

    That's going to be a royal pita.

    Why not just stop using different names for dev and prod?  It's easier to mess up the aliasing than it is 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".

  • RE: INDEX range_scan_count

    From Books Online, under sys.dm_db_index_operational_stats:

    sys.dm_db_index_operational_stats (Transact-SQL)range_scan_count  bigint  Cumulative count of range and table scans started on the index or heap.

    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: Table updates on large table with no ID or large gaps between IDs

    Go by the values in the clustered index.  For example, if the table is clustered on a datetime column, use that as the value for the UPDATE.

    Here's 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".

  • RE: Can someone explain how this works

    macbaze72 - Thursday, December 21, 2017 4:04 PM

    This code works, but I don;t understand it.  The part I need some clarification is...

    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: Suggestions on a query plan

    The key lookups should cost more than the sort for only 7 rows (I know the lookup is in both queries).  You should consider adding DateRegistered to the NC lindex.

    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 - 3,631 through 3,645 (of 7,619 total)