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 2008 Forums
 Transact-SQL (2008)
 Exit?

Author  Topic 

pareshmotiwala
Constraint Violating Yak Guru

323 Posts

Posted - 2010-07-27 : 08:17:04
I have the following subroutine:

out:
SELECT @error_code AS NativeErrorCode,
@RedGateExitCode AS RedGateCode,
@SQLErrorCode AS SQLCode
SET NOCOUNT OFF

--SELECT @out_code
exit(SELECT @out_code)
GO

This fails in sqlcmd/osql saying invalid syntax near Exit:
Does anybody have ideas?

If I uncomment the select @out_code, then I can run it via SSMS.


Regards
Paresh Motiwala
Boston, USA

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-07-27 : 11:50:33
Your requirement is not much clear for me.

A small clarifiction:
The extract is part of function or SP ?
Do you want to return any value from the routine ?

If its a function you can use return statement.
If its a SP then you can pass an output parameter and return the value.


If you requirement is something different then post more detailed info.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-07-27 : 12:09:15
quote:
Originally posted by pareshmotiwala

I have the following subroutine:

out:
SELECT @error_code AS NativeErrorCode,
@RedGateExitCode AS RedGateCode,
@SQLErrorCode AS SQLCode
SET NOCOUNT OFF

--SELECT @out_code
exit(SELECT @out_code)
GO

This fails in sqlcmd/osql saying invalid syntax near Exit:
Does anybody have ideas?

If I uncomment the select @out_code, then I can run it via SSMS.


Regards
Paresh Motiwala
Boston, USA



EXIT is not a valid TSQL command. You need to use RETURN.





CODO ERGO SUM
Go to Top of Page

pareshmotiwala
Constraint Violating Yak Guru

323 Posts

Posted - 2010-07-27 : 14:20:10
PK_Bohra: yes we want to return the value from the routines.
and Valentine Jones: This command is being used with SQLCMD utility and it seems is a valid command.

Thanks for the help.
BTW, this job has been running for ages, I just changed the server and recreated the job.
The new version of the server is SQL2008 R2/

Regards
Paresh Motiwala
Boston, USA
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-07-27 : 15:17:27
quote:
Originally posted by pareshmotiwala
Valentine Jones: This command is being used with SQLCMD utility and it seems is a valid command...



You should read SQL Server Books Online to see the actual syntax of the EXIT command within SQLCMD.



CODO ERGO SUM
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-07-27 : 15:22:05
and it's

Boston, MA USA *

* Home of the worse drivers in the Continental United States

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -