Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. A very terrifying stored procedure: how can you solve this issue really ???

A very terrifying stored procedure: how can you solve this issue really ???

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpasp-netdatabasehelpquestion
12 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H HaBiX

    The code is unreadable - please use formatting and actually write what the issue is..

    D Offline
    D Offline
    devenv exe
    wrote on last edited by
    #3

    Actually, it isn't me asking the question over there, so the code isn't mine. The first time i looked at that code, i just closed my eyes.

    "Coming soon"

    1 Reply Last reply
    0
    • D devenv exe

      http://forums.asp.net/p/1853860/5190798.aspx/1?Getting+last+record+duplicate+how+can+i+solve+this+issue+[^]

      "Coming soon"

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #4

      The cure for that is obvious: "get a new job"

      Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      F 1 Reply Last reply
      0
      • D devenv exe

        http://forums.asp.net/p/1853860/5190798.aspx/1?Getting+last+record+duplicate+how+can+i+solve+this+issue+[^]

        "Coming soon"

        B Offline
        B Offline
        BobJanova
        wrote on last edited by
        #5

        :omg:

        1 Reply Last reply
        0
        • D devenv exe

          http://forums.asp.net/p/1853860/5190798.aspx/1?Getting+last+record+duplicate+how+can+i+solve+this+issue+[^]

          "Coming soon"

          Z Offline
          Z Offline
          ZurdoDev
          wrote on last edited by
          #6

          Just COALESCE it. That fixes it every time.

          There are only 10 types of people in the world, those who understand binary and those who don't.

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            The cure for that is obvious: "get a new job"

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

            F Offline
            F Offline
            fjdiewornncalwe
            wrote on last edited by
            #7

            wouldyoulikefrieswiththat?

            I wasn't, now I am, then I won't be anymore.

            1 Reply Last reply
            0
            • D devenv exe

              http://forums.asp.net/p/1853860/5190798.aspx/1?Getting+last+record+duplicate+how+can+i+solve+this+issue+[^]

              "Coming soon"

              E Offline
              E Offline
              ENOTTY
              wrote on last edited by
              #8

              Here it is, in all its gory. A prime candidate for the use of inline TVFs, if there ever was one. At least that would give you the chance to argue about the correctness without going mad. And I'm not even mentioning the stringified params which should be DATETIME plus two other DATETIMEs split up as INTs. Curiously, in this guys world the default length for VARCHAR seems to be 100, not 50 (probably "just to make sure").

              USE [INVATTENDENCE] GO /****** Object: StoredProcedure [dbo].[SP_COST_OF_RESOURCE_MAN_POWER] Script Date: 10/25/2012 09:31:52 ******/

              SET ANSI_NULLS ON GO
              SET QUOTED_IDENTIFIER ON GO

              ALTER PROC [dbo].[SP_COST_OF_RESOURCE_MAN_POWER] (
              @IN_FDAY INT
              ,@IN_TDAY INT
              ,@IN_FMONTH INT
              ,@IN_TMONTH INT
              ,@IN_FYEAR INT
              ,@IN_TYEAR INT
              ,@IN_CONTRACTOR_ID INT
              ,@IN_TYPE VARCHAR(100)
              ,@IN_FROM_DATE VARCHAR(100)
              ,@IN_TO_DATE VARCHAR(100)
              ,@IN_CONTRACTOR_NAME VARCHAR(100)
              ,@IN_SITEID INT
              )
              AS
              BEGIN
              SELECT DISTINCT @IN_FROM_DATE AS FROM_DATE
              ,@IN_TO_DATE AS TO_DATE
              ,@IN_CONTRACTOR_NAME AS CONTRACTOR_NAME
              ,dbo.CONTRACTOR_SPECIFICATIONS.CONTRACTOR_NAME
              ,dbo.MANPOWER_CATEGORY.MAN_CAT_NAME
              ,SUM(CAST(CASE
              WHEN (
              ets.FIRST_SHIFT = 0
              OR ets.FIRST_SHIFT IS NULL
              )
              THEN 0
              ELSE ets.FIRST_SHIFT
              END AS DECIMAL(10, 1)) + CAST(CASE
              WHEN (
              ets.SECOND_SHIFT = 0
              OR ets.SECOND_SHIFT IS NULL
              )
              THEN 0
              ELSE ets.SECOND_SHIFT
              END AS DECIMAL(10, 1)) + CAST(CASE
              WHEN (
              ets.THIRD_SHIFT = 0
              OR ets.THIRD_SHIFT IS NULL
              )
              THEN 0
              ELSE ets.THIRD_SHIFT
              END AS DECIMAL(10, 1))) AS hrs_deployed
              ,CONVERT(DECIMAL(10, 1), (
              SUM(CAST(CASE
              WHEN (
              ets.FIRST_SHIFT IS NULL
              OR ets.FIRST_SHIFT = 0
              )
              THEN 0
              ELSE ets.FIRST_SHIFT
              END AS DECIMAL(10, 1))) + SUM(CAST(CASE
              WHEN (
              ets.SECOND_SHIFT IS NULL
              OR ets.SECOND_SHIFT = 0
              )
              THEN 0
              ELSE ets.SECOND_SHIFT
              END AS DECIMAL(10, 1))) + SUM(CAST(CASE
              WHEN (
              ets.THIRD_SHIFT IS NULL
              OR ets.THIRD_SHIFT = 0
              )
              THEN 0
              ELSE ets.THIRD_SHIFT
              END AS DECIMAL(10, 1)))
              ) / convert(DECIMAL(10, 2), dbo.RATE_SPECIFICATIONS_MAN.NO_OF_HR_BASIS)) AS days_worked
              ,convert(DECIMAL(10, 1), (
              CASE
              WHEN DBO.RATE_SPECIFICATIONS_MAN.STATUTORY_DUE_PAYABLE_BY = 'Contractor'
              THEN (
              CASE
              WHEN D

              B P G 3 Replies Last reply
              0
              • D devenv exe

                http://forums.asp.net/p/1853860/5190798.aspx/1?Getting+last+record+duplicate+how+can+i+solve+this+issue+[^]

                "Coming soon"

                B Offline
                B Offline
                Brisingr Aerowing
                wrote on last edited by
                #9

                :eek:

                I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking

                1 Reply Last reply
                0
                • E ENOTTY

                  Here it is, in all its gory. A prime candidate for the use of inline TVFs, if there ever was one. At least that would give you the chance to argue about the correctness without going mad. And I'm not even mentioning the stringified params which should be DATETIME plus two other DATETIMEs split up as INTs. Curiously, in this guys world the default length for VARCHAR seems to be 100, not 50 (probably "just to make sure").

                  USE [INVATTENDENCE] GO /****** Object: StoredProcedure [dbo].[SP_COST_OF_RESOURCE_MAN_POWER] Script Date: 10/25/2012 09:31:52 ******/

                  SET ANSI_NULLS ON GO
                  SET QUOTED_IDENTIFIER ON GO

                  ALTER PROC [dbo].[SP_COST_OF_RESOURCE_MAN_POWER] (
                  @IN_FDAY INT
                  ,@IN_TDAY INT
                  ,@IN_FMONTH INT
                  ,@IN_TMONTH INT
                  ,@IN_FYEAR INT
                  ,@IN_TYEAR INT
                  ,@IN_CONTRACTOR_ID INT
                  ,@IN_TYPE VARCHAR(100)
                  ,@IN_FROM_DATE VARCHAR(100)
                  ,@IN_TO_DATE VARCHAR(100)
                  ,@IN_CONTRACTOR_NAME VARCHAR(100)
                  ,@IN_SITEID INT
                  )
                  AS
                  BEGIN
                  SELECT DISTINCT @IN_FROM_DATE AS FROM_DATE
                  ,@IN_TO_DATE AS TO_DATE
                  ,@IN_CONTRACTOR_NAME AS CONTRACTOR_NAME
                  ,dbo.CONTRACTOR_SPECIFICATIONS.CONTRACTOR_NAME
                  ,dbo.MANPOWER_CATEGORY.MAN_CAT_NAME
                  ,SUM(CAST(CASE
                  WHEN (
                  ets.FIRST_SHIFT = 0
                  OR ets.FIRST_SHIFT IS NULL
                  )
                  THEN 0
                  ELSE ets.FIRST_SHIFT
                  END AS DECIMAL(10, 1)) + CAST(CASE
                  WHEN (
                  ets.SECOND_SHIFT = 0
                  OR ets.SECOND_SHIFT IS NULL
                  )
                  THEN 0
                  ELSE ets.SECOND_SHIFT
                  END AS DECIMAL(10, 1)) + CAST(CASE
                  WHEN (
                  ets.THIRD_SHIFT = 0
                  OR ets.THIRD_SHIFT IS NULL
                  )
                  THEN 0
                  ELSE ets.THIRD_SHIFT
                  END AS DECIMAL(10, 1))) AS hrs_deployed
                  ,CONVERT(DECIMAL(10, 1), (
                  SUM(CAST(CASE
                  WHEN (
                  ets.FIRST_SHIFT IS NULL
                  OR ets.FIRST_SHIFT = 0
                  )
                  THEN 0
                  ELSE ets.FIRST_SHIFT
                  END AS DECIMAL(10, 1))) + SUM(CAST(CASE
                  WHEN (
                  ets.SECOND_SHIFT IS NULL
                  OR ets.SECOND_SHIFT = 0
                  )
                  THEN 0
                  ELSE ets.SECOND_SHIFT
                  END AS DECIMAL(10, 1))) + SUM(CAST(CASE
                  WHEN (
                  ets.THIRD_SHIFT IS NULL
                  OR ets.THIRD_SHIFT = 0
                  )
                  THEN 0
                  ELSE ets.THIRD_SHIFT
                  END AS DECIMAL(10, 1)))
                  ) / convert(DECIMAL(10, 2), dbo.RATE_SPECIFICATIONS_MAN.NO_OF_HR_BASIS)) AS days_worked
                  ,convert(DECIMAL(10, 1), (
                  CASE
                  WHEN DBO.RATE_SPECIFICATIONS_MAN.STATUTORY_DUE_PAYABLE_BY = 'Contractor'
                  THEN (
                  CASE
                  WHEN D

                  B Offline
                  B Offline
                  Brisingr Aerowing
                  wrote on last edited by
                  #10

                  :eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek:

                  I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking

                  1 Reply Last reply
                  0
                  • E ENOTTY

                    Here it is, in all its gory. A prime candidate for the use of inline TVFs, if there ever was one. At least that would give you the chance to argue about the correctness without going mad. And I'm not even mentioning the stringified params which should be DATETIME plus two other DATETIMEs split up as INTs. Curiously, in this guys world the default length for VARCHAR seems to be 100, not 50 (probably "just to make sure").

                    USE [INVATTENDENCE] GO /****** Object: StoredProcedure [dbo].[SP_COST_OF_RESOURCE_MAN_POWER] Script Date: 10/25/2012 09:31:52 ******/

                    SET ANSI_NULLS ON GO
                    SET QUOTED_IDENTIFIER ON GO

                    ALTER PROC [dbo].[SP_COST_OF_RESOURCE_MAN_POWER] (
                    @IN_FDAY INT
                    ,@IN_TDAY INT
                    ,@IN_FMONTH INT
                    ,@IN_TMONTH INT
                    ,@IN_FYEAR INT
                    ,@IN_TYEAR INT
                    ,@IN_CONTRACTOR_ID INT
                    ,@IN_TYPE VARCHAR(100)
                    ,@IN_FROM_DATE VARCHAR(100)
                    ,@IN_TO_DATE VARCHAR(100)
                    ,@IN_CONTRACTOR_NAME VARCHAR(100)
                    ,@IN_SITEID INT
                    )
                    AS
                    BEGIN
                    SELECT DISTINCT @IN_FROM_DATE AS FROM_DATE
                    ,@IN_TO_DATE AS TO_DATE
                    ,@IN_CONTRACTOR_NAME AS CONTRACTOR_NAME
                    ,dbo.CONTRACTOR_SPECIFICATIONS.CONTRACTOR_NAME
                    ,dbo.MANPOWER_CATEGORY.MAN_CAT_NAME
                    ,SUM(CAST(CASE
                    WHEN (
                    ets.FIRST_SHIFT = 0
                    OR ets.FIRST_SHIFT IS NULL
                    )
                    THEN 0
                    ELSE ets.FIRST_SHIFT
                    END AS DECIMAL(10, 1)) + CAST(CASE
                    WHEN (
                    ets.SECOND_SHIFT = 0
                    OR ets.SECOND_SHIFT IS NULL
                    )
                    THEN 0
                    ELSE ets.SECOND_SHIFT
                    END AS DECIMAL(10, 1)) + CAST(CASE
                    WHEN (
                    ets.THIRD_SHIFT = 0
                    OR ets.THIRD_SHIFT IS NULL
                    )
                    THEN 0
                    ELSE ets.THIRD_SHIFT
                    END AS DECIMAL(10, 1))) AS hrs_deployed
                    ,CONVERT(DECIMAL(10, 1), (
                    SUM(CAST(CASE
                    WHEN (
                    ets.FIRST_SHIFT IS NULL
                    OR ets.FIRST_SHIFT = 0
                    )
                    THEN 0
                    ELSE ets.FIRST_SHIFT
                    END AS DECIMAL(10, 1))) + SUM(CAST(CASE
                    WHEN (
                    ets.SECOND_SHIFT IS NULL
                    OR ets.SECOND_SHIFT = 0
                    )
                    THEN 0
                    ELSE ets.SECOND_SHIFT
                    END AS DECIMAL(10, 1))) + SUM(CAST(CASE
                    WHEN (
                    ets.THIRD_SHIFT IS NULL
                    OR ets.THIRD_SHIFT = 0
                    )
                    THEN 0
                    ELSE ets.THIRD_SHIFT
                    END AS DECIMAL(10, 1)))
                    ) / convert(DECIMAL(10, 2), dbo.RATE_SPECIFICATIONS_MAN.NO_OF_HR_BASIS)) AS days_worked
                    ,convert(DECIMAL(10, 1), (
                    CASE
                    WHEN DBO.RATE_SPECIFICATIONS_MAN.STATUTORY_DUE_PAYABLE_BY = 'Contractor'
                    THEN (
                    CASE
                    WHEN D

                    P Offline
                    P Offline
                    Peter_in_2780
                    wrote on last edited by
                    #11

                    and that is why they invented TL;DR Cheers, Peter

                    Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                    1 Reply Last reply
                    0
                    • E ENOTTY

                      Here it is, in all its gory. A prime candidate for the use of inline TVFs, if there ever was one. At least that would give you the chance to argue about the correctness without going mad. And I'm not even mentioning the stringified params which should be DATETIME plus two other DATETIMEs split up as INTs. Curiously, in this guys world the default length for VARCHAR seems to be 100, not 50 (probably "just to make sure").

                      USE [INVATTENDENCE] GO /****** Object: StoredProcedure [dbo].[SP_COST_OF_RESOURCE_MAN_POWER] Script Date: 10/25/2012 09:31:52 ******/

                      SET ANSI_NULLS ON GO
                      SET QUOTED_IDENTIFIER ON GO

                      ALTER PROC [dbo].[SP_COST_OF_RESOURCE_MAN_POWER] (
                      @IN_FDAY INT
                      ,@IN_TDAY INT
                      ,@IN_FMONTH INT
                      ,@IN_TMONTH INT
                      ,@IN_FYEAR INT
                      ,@IN_TYEAR INT
                      ,@IN_CONTRACTOR_ID INT
                      ,@IN_TYPE VARCHAR(100)
                      ,@IN_FROM_DATE VARCHAR(100)
                      ,@IN_TO_DATE VARCHAR(100)
                      ,@IN_CONTRACTOR_NAME VARCHAR(100)
                      ,@IN_SITEID INT
                      )
                      AS
                      BEGIN
                      SELECT DISTINCT @IN_FROM_DATE AS FROM_DATE
                      ,@IN_TO_DATE AS TO_DATE
                      ,@IN_CONTRACTOR_NAME AS CONTRACTOR_NAME
                      ,dbo.CONTRACTOR_SPECIFICATIONS.CONTRACTOR_NAME
                      ,dbo.MANPOWER_CATEGORY.MAN_CAT_NAME
                      ,SUM(CAST(CASE
                      WHEN (
                      ets.FIRST_SHIFT = 0
                      OR ets.FIRST_SHIFT IS NULL
                      )
                      THEN 0
                      ELSE ets.FIRST_SHIFT
                      END AS DECIMAL(10, 1)) + CAST(CASE
                      WHEN (
                      ets.SECOND_SHIFT = 0
                      OR ets.SECOND_SHIFT IS NULL
                      )
                      THEN 0
                      ELSE ets.SECOND_SHIFT
                      END AS DECIMAL(10, 1)) + CAST(CASE
                      WHEN (
                      ets.THIRD_SHIFT = 0
                      OR ets.THIRD_SHIFT IS NULL
                      )
                      THEN 0
                      ELSE ets.THIRD_SHIFT
                      END AS DECIMAL(10, 1))) AS hrs_deployed
                      ,CONVERT(DECIMAL(10, 1), (
                      SUM(CAST(CASE
                      WHEN (
                      ets.FIRST_SHIFT IS NULL
                      OR ets.FIRST_SHIFT = 0
                      )
                      THEN 0
                      ELSE ets.FIRST_SHIFT
                      END AS DECIMAL(10, 1))) + SUM(CAST(CASE
                      WHEN (
                      ets.SECOND_SHIFT IS NULL
                      OR ets.SECOND_SHIFT = 0
                      )
                      THEN 0
                      ELSE ets.SECOND_SHIFT
                      END AS DECIMAL(10, 1))) + SUM(CAST(CASE
                      WHEN (
                      ets.THIRD_SHIFT IS NULL
                      OR ets.THIRD_SHIFT = 0
                      )
                      THEN 0
                      ELSE ets.THIRD_SHIFT
                      END AS DECIMAL(10, 1)))
                      ) / convert(DECIMAL(10, 2), dbo.RATE_SPECIFICATIONS_MAN.NO_OF_HR_BASIS)) AS days_worked
                      ,convert(DECIMAL(10, 1), (
                      CASE
                      WHEN DBO.RATE_SPECIFICATIONS_MAN.STATUTORY_DUE_PAYABLE_BY = 'Contractor'
                      THEN (
                      CASE
                      WHEN D

                      G Offline
                      G Offline
                      Gary Wheeler
                      wrote on last edited by
                      #12

                      For some inexplicable reason, that makes it worse.

                      Software Zen: delete this;

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups