SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 stored procedure within a stored procedure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sconard
Starting Member

18 Posts

Posted - 09/26/2012 :  14:35:33  Show Profile  Reply with Quote
I have done this before but cannot discern why this does not work.

From a query window opened from the db I write

update table1 set field1 = (spStoredProcedure1 field2)

spStoredProcedure1 (within same db) is passed t1.field2 and returns a value

The error message states syntax. I have tried exec and various syntax but no solution.

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 09/26/2012 :  14:42:51  Show Profile  Reply with Quote
Are you trying to capture the return value or a value from the result set from spStoredProcedure1 ?
Go to Top of Page

sconard
Starting Member

18 Posts

Posted - 09/26/2012 :  14:48:21  Show Profile  Reply with Quote
yes as the update is trying to set field1 to result
quote:
Originally posted by Lamprey

Are you trying to capture the return value or a value from the result set from spStoredProcedure1 ?

Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36782 Posts

Posted - 09/26/2012 :  14:56:10  Show Profile  Visit tkizer's Homepage  Reply with Quote
Put the return or output value into a variable and then use the variable for the update command.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sconard
Starting Member

18 Posts

Posted - 09/26/2012 :  14:59:13  Show Profile  Reply with Quote
The return value varies based on the input value of the update query. Updating an entire table of values in one field.

IE update table1 set field1 = field2 will update an entire table of values for field1.
quote:
Originally posted by tkizer

Put the return or output value into a variable and then use the variable for the update command.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Edited by - sconard on 09/26/2012 15:00:57
Go to Top of Page

robvolk
Most Valuable Yak

USA
15659 Posts

Posted - 09/26/2012 :  15:24:46  Show Profile  Visit robvolk's Homepage  Reply with Quote
You could rewrite the stored procedure as a user-defined function (provided it doesn't make any permanent system changes like inserting/deleting/updating another table) and use it like this:
update table1 set field1 = dbo.myUDF(field2)
If you post the code of the stored procedure we could help with the translation.
Go to Top of Page

sconard
Starting Member

18 Posts

Posted - 09/27/2012 :  10:12:29  Show Profile  Reply with Quote
And I should have thought of using a function. Worked perfect as

UPDATE table1
SET field1 = function1(field2)

this may not have been the most efficient method but it was a one off.
Thanks!
quote:
Originally posted by robvolk

You could rewrite the stored procedure as a user-defined function (provided it doesn't make any permanent system changes like inserting/deleting/updating another table) and use it like this:
update table1 set field1 = dbo.myUDF(field2)
If you post the code of the stored procedure we could help with the translation.

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.19 seconds. Powered By: Snitz Forums 2000