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

different with the variables Expand / Collapse
Author
Message
Posted Sunday, December 22, 2013 6:55 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Saturday, December 28, 2013 6:04 AM
Points: 107, Visits: 940
Hi
what is the difference between these 2 variables in store procedure:
1- the variables before As[/size]
2- the variable with declare[size="7"]
after As[size="7"][/size]
thanks alot
Post #1525353
Posted Sunday, December 22, 2013 8:11 AM


SSC-Insane

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

Group: General Forum Members
Last Login: Today @ 7:23 PM
Points: 20,860, Visits: 32,883
Care to provide a better description of the question?

I am not sure if you are asking what the difference between the parameters declared as input/output to the procedure and variables declared locally to the procedure, which is what it sounds like you are asking.



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 #1525358
Posted Sunday, December 22, 2013 2:00 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 7:27 AM
Points: 35,769, Visits: 32,437
nazaninahmady_sh (12/22/2013)
Hi
what is the difference between these 2 variables in store procedure:
1- the variables before As
2- the variable with declare after As
thanks alot


The variables before the "AS" are paremeters that you can pass into the stored procedure.

The variables with the DECLARE that come after the "AS" are local variables to the procedure.

I strongly recommend that you get into SSMS , press the {f1} key to get into "Books Online" (the help system that comes with SQL Server), and do a search for "CREATE PROCEDURE" to learn more about the different parts of Stored Procedures and how to build them correctly.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1525380
Posted Monday, December 23, 2013 8:18 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:22 AM
Points: 14,205, Visits: 28,534
Also know that the optimizer, with one exception, treats a parameter (before the AS) and a variable (after the AS) differently. A parameter value is known to the optimizer when it compiles the query since the parameter has to be passed with the execution statement, while a variable value is not known (except in the case of a recompile, the one exception). The known values are used to compare against the statistics to arrive at a more specific plan for the data being passed. This process is known as parameter sniffing. A variable, because it's value is unknown, will get an average plan based on an average of the statistics (except, again, in the case of recompiles).

----------------------------------------------------
"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
Post #1525561
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse