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. update with random value

update with random value

Scheduled Pinned Locked Moved Database
questionannouncementlounge
2 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.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    Hi, I have a field called stock_value and I want to update the value with either 10 or 20 so t should list the records in random way then update the first as 10, second as 20, thrid as 10, fourth as 20 etc until end of records.. How can I do this? Thanks, Jassim

    J 1 Reply Last reply
    0
    • J Jassim Rahma

      Hi, I have a field called stock_value and I want to update the value with either 10 or 20 so t should list the records in random way then update the first as 10, second as 20, thrid as 10, fourth as 20 etc until end of records.. How can I do this? Thanks, Jassim

      J Offline
      J Offline
      Jorgen Andersson
      wrote on last edited by
      #2

      You don't say what database you're using, so I'll assume it's SQL-Server. Random ordering you can get by making a variation of this query:

      SELECT * FROM table ORDER BY NEWID()

      Then you can use the CASE and MOD operators to update every second row.

      Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

      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