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
 General SQL Server Forums
 New to SQL Server Programming
 Query Analyzer

Author  Topic 

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2008-10-20 : 10:00:29
In query analyizer, how do I run a stored procedure with a parameter

I know exec storedprocedurename will execute it but not sure how to add parameters

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-10-20 : 10:04:53
exec DT_name 'paramater'
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-10-20 : 10:06:39
if there are more than 1 parameters,
exec DT_name 'paramater1','paramater2','paramater3'
Go to Top of Page

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2008-10-20 : 10:20:00
thank you
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-10-20 : 11:04:05
Don't know if you are still monitoring this, or if you care but you can also do this (useful if you have a bunch of optional parameters and good for debugging / readability)


EXEC ,procedureName]>
@param1 = x
, @param2 = y
, @param5 = z

Where @param is the name of the paramater declared by the sp.

Example:

CREATE PROCEDURE displayText (
@text NVARCHAR(MAX)
, @startPos INT = 0
, @endPos INT = 100
)
AS BEGIN
PRINT SUBSTRING(@text, @startPos, @endPos)
END
GO

-- All params
EXEC displayText
@text = 'foo000000000000000000000'
, @startPos = 2
, @endPos = 10

-- Only esential params
EXEC displayText
@text = 'foo000000000000000000000'

-- 1 of the optional params
EXEC displayText
@text = 'foo000000000000000000000'
, @endPos = 10


-------------
Charlie
Go to Top of Page
   

- Advertisement -