SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Parameter passing


Parameter passing

Author
Message
thaya2002
thaya2002
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 44
hi guys,
i know how to pass input parameter to stored procs.
why do we use output parameters in stored procs?
would anyone suggest an example for that kind of stored procs?

other question is about dynamic sql
can i able to use the where clause in dynamic sql?
eg: 'select gemName,gemType,State
from GEmTable where country=%A'

when i used dynamic sql in my scripts using where clause,i had an error message.

thank you very much for your time.

regards,
thaya
Steve Jones
Steve Jones
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: Administrators
Points: 63698 Visits: 19115
An output parameter can be used to assign a variable the result of a stored procedure. Less used now that we have user-defined functions.

For dynamic Sql, it's something like

declare @cmd varchar(8000), @a char(2)
select @a = 'US'

select @cmd = 'select gemName,gemType,State
from GEmTable where country=' + @A

exec(@cmd)


That's dynamic SQL. A regular query would be

select gemName, gemType, State from GemTable where country = @a

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Grant Fritchey
Grant Fritchey
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40619 Visits: 32666
I'm pretty sure I'm old fashioned, but I still use OUTPUT parameters in some situations. Let's say you have a situation where the application normally creates a row in a table and then creates rows in the child table. The usual call is to spcTable1 which returns the SCOPE_IDENTITY for the row it inserted and the app then passes this on to spcTable2. But what if you also have to support a set based approach where you receive an XML file or something and need to process the same procedures in a single stored proc:

Declare @MyId int
EXEC spcTable1 @Param1 = 'SomeValue', @Param2 = @MyId OUTPUT
--this executes the procedure and captures the output which you then pass on to the next proc

EXEC spcTable2 @Param3 = @MyId



It's a simplistic example, but it gives you the idea.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search