Click here to Skip to main content
15,888,733 members

how to pass parameters for searching in stored procedure

Priyaaammu asked:

Open original thread
Hi..
Following is my stored procedure using cursor,
SQL
create procedure [dbo].[usp_SampleProcedure]
as
begin
	declare @empname	varchar(50)
	declare @emplocation	varchar(50)
	declare @deptname	varchar(50)
	declare	@basicsalary	int
	declare	@hra	int
	declare @total	int
	declare @grade	varchar(100)
	declare @dob	datetime
	declare	@doj	datetime
	declare cur_EmployeeDetails cursor for select * from view_EmployeeDetails
	if exists (select * from sys.tables where sys.tables.name like '%#TempTable%')
	  begin
  		  drop table #TempTable
	  end
    else
	begin
		create table #TempTable(empname	varchar(50),emplocation	varchar(50),deptname varchar(50),basicsalary int,hra int,
		netsalary int,grade	varchar(50),dob	datetime,doj datetime)
	end
    --*********Cursor Open*********
      open cur_EmployeeDetails
      begin
		  fetch cur_EmployeeDetails into @empname,@emplocation,@deptname,@basicsalary,@dob,@doj
	    
		   while @@FETCH_STATUS=0
		   begin
			  set @hra=@basicsalary*23/100
			  set @total=@basicsalary + @hra
			  if(@total>17000)
				 begin
				   set @grade='A'
				 end
			   else 
		  		  begin
					set @grade='B'
				  end

			   insert into #TempTable (empname,emplocation,deptname,basicsalary,hra,netsalary,grade,dob,doj)
			                    values(@empname,@emplocation,@deptname,@basicsalary,@hra,@total,@grade,@dob,@doj)

				fetch  cur_EmployeeDetails into @empname,@emplocation,@deptname,@basicsalary,@dob,@doj
		     end
        end
        close cur_EmployeeDetails
        deallocate cur_EmployeeDetails
       --*********Cursor Closing*********
       select 
          empname as EmpName,emplocation as EmpLocation,deptname as DeptName,basicsalary as BasicSalary,hra as HRA,
          netsalary as Total,grade as Grade,convert (varchar(50),dob,103) as DOB,convert (varchar(50),doj,103) as DOJ 
        from #TempTable 
end

Now i want to pass three input parameters as dept,dateofbirth and dateofjoining for searching options.
I dont know how to pass date as filter options...guide me
Tags: SQL

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900