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. Database & SysAdmin
  3. Database
  4. Question Update a Query with Case When Data

Question Update a Query with Case When Data

Scheduled Pinned Locked Moved Database
questiondatabaseannouncement
4 Posts 2 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.
  • P Offline
    P Offline
    pdnet
    wrote on last edited by
    #1

    suppose My Query Like Select x.srlNo,x.ProductID from (Select Srlno,ProductID,SaleType from SaleDetail)as x where X.Srlno in (Select Y.SrlNo-1 from(Select SrlNo from SaleDetail where SaleType=5) as Y) "It is Just One Row value I am Specify, Actually it is generate Dynamicaly" How Can I Modifying my field through Case When. I want to Modify some field of the Current Row with the Privious row data in my Query

    Arindam Banerjee Sr. Software Developer Rance Computer Pvt Ltd. Kolkata (India)

    W 1 Reply Last reply
    0
    • P pdnet

      suppose My Query Like Select x.srlNo,x.ProductID from (Select Srlno,ProductID,SaleType from SaleDetail)as x where X.Srlno in (Select Y.SrlNo-1 from(Select SrlNo from SaleDetail where SaleType=5) as Y) "It is Just One Row value I am Specify, Actually it is generate Dynamicaly" How Can I Modifying my field through Case When. I want to Modify some field of the Current Row with the Privious row data in my Query

      Arindam Banerjee Sr. Software Developer Rance Computer Pvt Ltd. Kolkata (India)

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      pdnet wrote:

      It is Just One Row value I am Specify, Actually it is generate Dynamicaly" How Can I Modifying my field through Case When

      pdnet wrote:

      I want to Modify some field of the Current Row with the Privious row data in my Query

      If you're using SQL Server, that won't work unless you create a function and store the value from the previous row. Also you may have trouble defining which is the previous row since typically the rows are coming in random order. Perhaps you should write a little example with data, what you're trying to achieve.

      The need to optimize rises from a bad design.My articles[^]

      P 1 Reply Last reply
      0
      • W Wendelius

        pdnet wrote:

        It is Just One Row value I am Specify, Actually it is generate Dynamicaly" How Can I Modifying my field through Case When

        pdnet wrote:

        I want to Modify some field of the Current Row with the Privious row data in my Query

        If you're using SQL Server, that won't work unless you create a function and store the value from the previous row. Also you may have trouble defining which is the previous row since typically the rows are coming in random order. Perhaps you should write a little example with data, what you're trying to achieve.

        The need to optimize rises from a bad design.My articles[^]

        P Offline
        P Offline
        pdnet
        wrote on last edited by
        #3

        Suppose My Data Looks Like : SrlNo Type ProductID Group 1 1 1.0 A 2 1 2.0 B 3 2 3.0 C 4 1 4.0 A I Want to Update This Data in My Query in this way that "If the Type of the Product is 2 then It is Replaced by the Previous Product's Group" That means : SrlNo Type ProductID Group 1 1 1.0 A 2 1 2.0 B 3 2 3.0 B 4 1 4.0 A

        Arindam Banerjee Sr. Software Developer Rance Computer Pvt Ltd. Kolkata (India)

        W 1 Reply Last reply
        0
        • P pdnet

          Suppose My Data Looks Like : SrlNo Type ProductID Group 1 1 1.0 A 2 1 2.0 B 3 2 3.0 C 4 1 4.0 A I Want to Update This Data in My Query in this way that "If the Type of the Product is 2 then It is Replaced by the Previous Product's Group" That means : SrlNo Type ProductID Group 1 1 1.0 A 2 1 2.0 B 3 2 3.0 B 4 1 4.0 A

          Arindam Banerjee Sr. Software Developer Rance Computer Pvt Ltd. Kolkata (India)

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          You can use CASE to modify the result based on the value, like:

          SELECT
          ...
          CASE
          WHEN (Type = 2) THEN (SELECT Group FROM TableName WHERE ???)
          ELSE Group
          END,
          ...
          FROM TableName

          but the problem is, how you identify the previous product group? There should be somekind of logic for that.

          The need to optimize rises from a bad design.My articles[^]

          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