Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Return Code from EXEC sp_executesql

Author  Topic 

dije
Starting Member

6 Posts

Posted - 2011-09-15 : 22:47:08
Dear All,

Here the situation :

1. DECLARE @RC int
EXEC @RC=t1_INSERT 1,1
SELECT @RC AS [RC_Parent]

2. DECLARE @RC int
DECLARE @SQL nvarchar(500)
SET @SQL=N't1_INSERT 1,1'
SET @RC=0
EXEC @RC=sp_executesql @SQL
SELECT @RC AS [RC_Parent]


on scheme No. #1, i can get value from variable @RC (Return Code).
on scheme No. #2, variable @RC always return 0...???
what should i do to get @RC value on scheme #2...??


thx All,

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-09-15 : 22:55:02
You'll need to use the OUTPUT option of sp_executesql. See Books Online for details and examples.

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

Subscribe to my blog
Go to Top of Page

dije
Starting Member

6 Posts

Posted - 2011-09-15 : 23:05:58
thank's tara...

i used SQL 2000, i can't find OUTPUT option of sp_executesql...
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-09-15 : 23:10:12
I haven't used 2000 in ages, sorry. Not sure that you can do what you want there.

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

Subscribe to my blog
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-09-15 : 23:41:28
[code]
DECLARE @RC int
DECLARE @SQL nvarchar(500)
SET @SQL=N'EXEC @RC=t1_INSERT 1,1'
SET @RC=0
EXEC sp_executesql @SQL, N'@RC int OUTPUT', @RC OUTPUT
SELECT @RC AS [RC_Parent]
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

dije
Starting Member

6 Posts

Posted - 2011-09-15 : 23:47:11
Dear tkzer & khtan,

It's work..!!!

thx a lot...
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-09-16 : 00:42:58
That's weird that BOL for 2000 doesn't show this option available, yet it works.

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

Subscribe to my blog
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-09-16 : 01:19:59
you mean the OUTPUT option ?

Just check the SQL 2000 BOL, it is not stated at all. And I have been using sp_executesql with OUTPUT parameter on SQL 2000 for ages and didn't realize this


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-09-16 : 01:54:11
Yeah that's why I replied like I did initially as I looked it up and saw it was missing. I don't have 2000 around to have tested it, so I figured if BOL doesn't mention it then it must not have existed back then. I don't think I started using it until 2005.

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

Subscribe to my blog
Go to Top of Page
   

- Advertisement -