Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Parameter passing Expand / Collapse
Author
Message
Posted Wednesday, February 6, 2008 4:00 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, April 12, 2010 11:09 PM
Points: 15, 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
Post #452480
Posted Wednesday, February 6, 2008 8:03 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 1:24 PM
Points: 33,051, Visits: 15,157
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
Post #452526
Posted Thursday, February 7, 2008 5:44 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 12:29 PM
Points: 15,501, Visits: 27,886
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 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #452671
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse