|
INTERVIEW QUESTIONS
DATABASE
MS SQL SERVER
DETAILS
Question: What Are the Advantages of Passing Name-Value Pairs as Parameters?
Answer: When calling a stored procedure defined with parameters, you can pass values to those parameters in two ways:
* Passing only values in the same order as parameters defined in the stored procedure. * Passing name-value pairs in any order.
The advantages of passing name-value pairs to stored procedure parameters are:
* Makes the calling statement more readable - You know which value is passed to which parameter. * Makes it possible to pass values in an order different than how parameters are defined.
The tutorial exercise shows you some good examples of passing name-value pairs as parameters:
CREATE PROCEDURE diff_in_days @start_date DATETIME, @end_date DATETIME AS BEGIN PRINT CONVERT(VARCHAR(20),@end_date,107) + ' - ' + CONVERT(VARCHAR(20),@start_date,107) + ' = ' + STR(DATEDIFF(DAY, @start_date, @end_date)); END; GO
EXEC diff_in_days '01-Jan-2007', '19-May-2007'; GO May 19, 2007 - Jan 01, 2007 = 138
EXEC diff_in_days @start_date='01-Jan-2007', @end_date='19-May-2007'; GO May 19, 2007 - Jan 01, 2007 = 138
-- Name-value pairs can be given in any order EXEC diff_in_days
|
|
|
Category |
MS SQL Server Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 7759 users |
Added on |
9/24/2014 |
Views |
68677 |
Rate it! |
|
|
Question:
What Are the Advantages of Passing Name-Value Pairs as Parameters?
Answer:
When calling a stored procedure defined with parameters, you can pass values to those parameters in two ways:
* Passing only values in the same order as parameters defined in the stored procedure. * Passing name-value pairs in any order.
The advantages of passing name-value pairs to stored procedure parameters are:
* Makes the calling statement more readable - You know which value is passed to which parameter. * Makes it possible to pass values in an order different than how parameters are defined.
The tutorial exercise shows you some good examples of passing name-value pairs as parameters:
CREATE PROCEDURE diff_in_days @start_date DATETIME, @end_date DATETIME AS BEGIN PRINT CONVERT(VARCHAR(20),@end_date,107) + ' - ' + CONVERT(VARCHAR(20),@start_date,107) + ' = ' + STR(DATEDIFF(DAY, @start_date, @end_date)); END; GO
EXEC diff_in_days '01-Jan-2007', '19-May-2007'; GO May 19, 2007 - Jan 01, 2007 = 138
EXEC diff_in_days @start_date='01-Jan-2007', @end_date='19-May-2007'; GO May 19, 2007 - Jan 01, 2007 = 138
-- Name-value pairs can be given in any order EXEC diff_in_days Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How To Provide Values to Stored Procedure Parameters in MS SQL Server?
|
View Answer
|
|
How To Create Stored Procedures with Parameters in MS SQL Server?
|
View Answer
|
|
How To Modify an Existing Stored Procedure in MS SQL Server?
|
View Answer
|
|
How To Get the Definition of a Stored Procedure Back?
|
View Answer
|
|
How To Generate CREATE PROCEDURE Script on an Existing Stored Procedure?
|
View Answer
|
|
How To End a Stored Procedure Properly in MS SQL Server?
|
View Answer
|
|
How To Create a Stored Procedure with a Statement Block in MS SQL Server?
|
View Answer
|
|
How To Drop an Existing Stored Procedure in MS SQL Server?
|
View Answer
|
|
How To List All Stored Procedures in the Current Database using MS SQL Server?
|
View Answer
|
|
How To Execute a Stored Procedure in MS SQL Server?
|
View Answer
|
|
How To Create a Simple Stored Procedure in MS SQL Server?
|
View Answer
|
|
How To Create an Index on a View?
|
View Answer
|
|
How To Bind a View to the Schema of the Underlying Tables?
|
View Answer
|
|
How Column Data Types Are Determined in a View?
|
View Answer
|
|
How To Assign New Column Names in a View?
|
View Answer
|
|
Can We Delete Data from a View?
|
View Answer
|
|
Can We Update Data in a View?
|
View Answer
|
|
Can We Insert Data into a View?
|
View Answer
|
|
How To Modify the Underlying Query of an Existing View?
|
View Answer
|
|
Can You Use ORDER BY When Defining a View?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All MS SQL Server Interview Questions & Answers - Exam Mode /
Learning Mode
|