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 clause using if condition

Update clause using if condition

Scheduled Pinned Locked Moved Database
sysadminhelpannouncement
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.
  • N Offline
    N Offline
    n_gchaitra
    wrote on last edited by
    #1

    I have written following sqlstatements to update a column based on the no of days between two dates. but it is giving the error, Server: Msg 512, Level 16, State 1, Line 2 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. In what other way i can get the expected result if (select datediff(dd,transactiondate, Issuedate) from receipt)>365 begin update receipt set longvalue=datediff(dd,transactiondate, Issuedate) end else begin update receipt set shortvalue=datediff(dd,transactiondate, Issuedate) end

    Chaitra N

    C 1 Reply Last reply
    0
    • N n_gchaitra

      I have written following sqlstatements to update a column based on the no of days between two dates. but it is giving the error, Server: Msg 512, Level 16, State 1, Line 2 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. In what other way i can get the expected result if (select datediff(dd,transactiondate, Issuedate) from receipt)>365 begin update receipt set longvalue=datediff(dd,transactiondate, Issuedate) end else begin update receipt set shortvalue=datediff(dd,transactiondate, Issuedate) end

      Chaitra N

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Use a WHERE in the UPDATE

      UPDATE receipt set longvalue=datediff(dd,transactiondate, Issuedate)
      WHERE datediff(dd,transactiondate, Issuedate) >365

      UPDATE receipt set shortvalue=datediff(dd,transactiondate, Issuedate)
      WHERE datediff(dd,transactiondate, Issuedate) <= 365


      Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

      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