SQL Server BasicsWhat is SQL Server database?What is RDBMS?What is Normalization?Why we use Denormalization?What_is_SQL?What is PL/SQL?Difference between SQL and PL/SQLDatabase TableOne to One RelationshipOne to Many RelationshipMany to Many RelationshipMany to One RelationshipString Data TypesNumber Data TypesDate Data TypesOther Data TypesCreate DatabaseDrop DatabaseCreating and Managing Users in SQL ServerCreate TableAlter TableDrop TableConstraints in SQL serverPrimary KeyForeign KeyUnique KeyCandidate KeyComposite KeyDifference between primary key and candidate keyPrimary key and foreign key relationshipSurrogate KeyCascading Referential Integrity ConstraintsSelf Referential Integrity ConstraintsInsert into statementInsert multiple recordsUpdate statementDelete statementTruncate statementDifference between Delete and TruncateAlias in SQL ServerSelect statementSelect DistinctSelect TopSelect IntoNull Functions(ISNULL(),NULLIF(),COALESCE())Sub QueryIdentity ColumnSequence objectDifference between sequence and identity columnSQL Server ClausesWHERE ClauseOrder By ClauseTop N ClauseGroup By ClauseHaving ClauseDifference between Where and HavingSQL Server OperatorsArithmetic OperatorsComparison OperatorsLogical OperatorsBitwise OperatorsAny OperatorsAll OperatorsUnion OperatorsUnion All OperatorsDifference between Union and Union AllIntersect OperatorExcept OperatorDifference between Except and IntersectJoinsInner JoinLeft JoinRight JoinFull JoinSelf JoinCross JoinViewsWhat are views?Create views using SSMSIndexed ViewsComplex ViewsCheck Option in ViewCheck Encryption in ViewSchema Binding Option in ViewRead-only ViewsUpdatable ViewsAdvantages and disadvantages of viewsCreate multiple views on one tableCan we implement index on views?Can we Perform Insert, update, delete operation on views?Stored Procedure and FunctionsWhat are Stored Procedures?Why we use stored procedures?Passing parameters to Stored procedureUser-Defined FunctionsDifference between UDF and Stored procedurePre-Defined Functions@@Indentity and Scope_IndentityNULLIF, ISNULL and COALESCE

How to pass parameters to Stored procedures?

To pass parameters to a stored procedure in SQL Server, you can define input parameters in the stored procedure's declaration and then provide values for those parameters when executing the stored procedure. Here's an example:

Creating a stored procedure with parameters:


CREATE PROCEDURE GetEmployeesByDepartment
    @DepartmentID INT
AS
BEGIN
    SELECT EmployeeID, FirstName, LastName, Salary
    FROM Employees
    WHERE DepartmentID = @DepartmentID
END

In this example, we're creating a stored procedure named "GetEmployeesByDepartment" that expects a single input parameter, @DepartmentID, of type INT.

Executing the stored procedure with parameter values:

To execute the stored procedure and pass the parameter values, you can use the EXEC statement.


EXEC GetEmployeesByDepartment @DepartmentID = 123

In this case, we're passing the value 123 as the @DepartmentID parameter to the stored procedure.

The stored procedure will execute the SQL statement inside it, using the provided parameter value to filter the results. It will return the details of employees who belong to the specified department.

You can also pass parameters positionally instead of using named parameters:


EXEC GetEmployeesByDepartment 123

Here, the value 123 is provided as the first parameter, which corresponds to the @DepartmentID parameter based on its position in the stored procedure declaration.

Note: In addition to input parameters, stored procedures in SQL Server can have output parameters and even return result sets. Input parameters are used to pass values into the stored procedure, output parameters are used to return values from the stored procedure, and result sets are returned by executing queries within the stored procedure.