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. How to call stored procedure from update statement

How to call stored procedure from update statement

Scheduled Pinned Locked Moved Database
databasetutorialquestionannouncement
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.
  • I Offline
    I Offline
    iluha
    wrote on last edited by
    #1

    Hello, I have a stored procedure called P_DATE_TO_MS that takes 2 parameters DATE & MILLISECOND and I need to call this procedure from an update statement: conConnection.Execute ("UPDATE table SET CURRENT_TIME_IN_MS = P_DATE_TO_MS(getDate()) WHERE id=123") It looks like the stored procedure returns the information in the second variable (ByRef?) and not as a return value. I'm calling the statement through ADODB.Connection object and not in the SQL directly. Please correct me if my assumption is incorrect, I'm not an SQL guy and I'm just getting into SQL Can anyone tell me if this is possible or how to do it. here is the store procedure: CREATE PROCEDURE P_DATE_TO_MS @DATE DATETIME, @MILLISECOND DECIMAL OUTPUT SET @MILLISECOND = TIME_IN_MS END GO Thank you in advance ilya

    N 1 Reply Last reply
    0
    • I iluha

      Hello, I have a stored procedure called P_DATE_TO_MS that takes 2 parameters DATE & MILLISECOND and I need to call this procedure from an update statement: conConnection.Execute ("UPDATE table SET CURRENT_TIME_IN_MS = P_DATE_TO_MS(getDate()) WHERE id=123") It looks like the stored procedure returns the information in the second variable (ByRef?) and not as a return value. I'm calling the statement through ADODB.Connection object and not in the SQL directly. Please correct me if my assumption is incorrect, I'm not an SQL guy and I'm just getting into SQL Can anyone tell me if this is possible or how to do it. here is the store procedure: CREATE PROCEDURE P_DATE_TO_MS @DATE DATETIME, @MILLISECOND DECIMAL OUTPUT SET @MILLISECOND = TIME_IN_MS END GO Thank you in advance ilya

      N Offline
      N Offline
      Nic Rowan
      wrote on last edited by
      #2

      Hi, I think a user defined function would work better for what you are trying to do (a SCALAR FUNCTION in this case) CREATE FUNCTION dbo.udfGetSeconds (@Days INT) RETURNS INT AS BEGIN DECLARE @Seconds INT SET @Seconds = @Days * 24 * 60 * 60 RETURN @Seconds END Then use it as follows SELECT dbo.udfGetSeconds(5) (edit) or in an UPDATE statement UPDATE [Table] SET [column] = dbo.udfGetSeconds(5) (edit)


      The man who smiles when things go wrong has thought of someone he can blame it on. If you tell a man there are 300 billion stars in the universe, he'll believe you. But if you tell him a bench has just been painted, he'll have to touch it to be sure.


      -- modified at 8:03 Thursday 6th October, 2005

      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