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

Stored procedure call syntax Expand / Collapse
Author
Message
Posted Friday, February 22, 2013 11:30 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 1:24 PM
Points: 1,774, Visits: 3,216
When calling stored procedures with input parameters, do I need to declare variables or not before the execute command, I don't usually, but I see in SSMS when generating the script for execute sproc, it declares all the variables before call the sproc.
Post #1423184
Posted Friday, February 22, 2013 11:47 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 12:15 PM
Points: 43,017, Visits: 36,179
Depends what you're doing, where the values for the proc come from, whether there are output procedures, etc.


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1423195
Posted Friday, February 22, 2013 11:53 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 1:24 PM
Points: 1,774, Visits: 3,216
I just do a simple call to a stored procedure with 3 input parameters in ssms,
no output value.

for example I just want to execute sp_WhoIsActive with some input parameters in SSMS,
and it returns the result at the grid. I guess it is not requried to declare parameters data type, unless it will reused after execute statement, is that correct?

In SSMS, when generating script, it always declare the datatype of parameters, so wondered if it is required.

Thanks
Post #1423201
Posted Friday, February 22, 2013 3:36 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 1:25 PM
Points: 23,396, Visits: 32,236
I let SSMS generate the script to run a stored proc, and I get this:


DECLARE @RC int
DECLARE @DDVersion varchar(20)

-- TODO: Set parameter values here.

EXECUTE @RC = [cidne2110].[dbo].[spDDAddFixAll]
@DDVersion
GO


I edit the code like this, then execute it:


DECLARE @RC int
DECLARE @DDVersion varchar(20) = '2.1.10'

-- TODO: Set parameter values here.

EXECUTE @RC = [cidne2110].[dbo].[spDDAddFixAll]
@DDVersion
GO


This would be the same thing:


EXECUTE dbo.spDDAddFixAll '2.1.10'
GO





Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1423282
Posted Friday, February 22, 2013 3:59 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 1:24 PM
Points: 1,774, Visits: 3,216
Thanks, yes, I tried those earlier and knew they all work, but just want to confirm my question on my previous post.
Post #1423285
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse