This
article will show you how you can user if statement in you sql stored
procedure to execute query on the bases of passed parameter.
Some of my
previous articles are as follows: Get
Year, Month, Date From Date in SQL, SQL
Query To Drop or Delete All Table, View, Stored Procedure and Trigger, Insert,
Update, Delete, Select, Drop and Create Table In Ms Sql Server Database Table, Bind
and Validate GridView TextBox Value by jQuery In Asp.Net Using C#, Asp.Net
Login Form With User Role Selection By Dropdownlist In Asp.net Using C#.Net, How
to reset your lost sql sa password | Reset SQL Server sa password by Windows
Authentication
So here SP
with if statement.
SET ANSI_NULLS
ON
GO
SET QUOTED_IDENTIFIER
ON
GO
CREATE PROCEDURE
SP_Demo
@Type int
AS
BEGIN
if(@Type=1)
Begin
Select * from DemoTable1
END
Else
Begin
Select * from DemoTable2
End
GO
|
In above I have taken a @Type variable in this
user will pass the value and on the bases of the value SP will execute the
related query.
0 comments:
Please let me know your view