Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner's Question Re Stored Procedure Parameter 1

Status
Not open for further replies.

xweyer

MIS
Sep 7, 2000
140
US
I'm trying to understand the following code.

"CREATE Procedure Adjustment @wSNN varchar(9)='%'"

My question is what is the purpose of ='%'? I know that a parameter named wSNN of variable type varchar(9) is created but from reviewing command syntax I'm left with the perception that ='%' would mean the default value of wSNN is equal to '%'. ...meaning a wildcard?

What does this bit of code actually accomplish?


 
When a parameter is followed by = (something), you end up with an optional parameter. If the parameter is omitted, then (in this case), % is passed in its place.

Take a look at this example:

Code:
[COLOR=blue]Create[/color] [COLOR=blue]Procedure[/color] TestOptionalParameter @Param1 [COLOR=blue]VarChar[/color](9) = [COLOR=red]'%'[/color]
[COLOR=blue]As[/color]
[COLOR=blue]Select[/color] @Param1

[COLOR=blue]Exec[/color] TestOptionalParameter [COLOR=red]'Hello World'[/color]
[COLOR=green]-- Returns: Hello Wor
[/color]
[COLOR=blue]Exec[/color] TestOptionalParameter NULL
[COLOR=green]-- returns: NULL
[/color]
[COLOR=blue]Exec[/color] TestOptionalParameter 
[COLOR=green]-- Returns: %[/color]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks for the example, gmmastros. That clarifies things for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top