Tuesday, April 9, 2013

Sql stored procedure fatch all record if we pass blank parameter

Here question is How to create sql query or stored procedure to find result based on parameter passed. If we pass blank value parameter then all record fetch other wise record fatch based on parameter value..

Here I create example for better understanding :

First we create table employee

Create table employee ( empid int, ename varchar(20)
)

Insert into emploee(empid,ename)
Select 1, sanjay
Union
Select 2, 'raju'
Union
Select 3, 'ravi'

Now create stored procedure for get record of employee based on parameter eid..

Create procedure getemp
@eid int
As
Begin
Select eid, ename from employee where ''=@eid or eid= @eid
End

Here if we pass Blank value  for. @eid paramer

As.   getemp ' '

Then all record get..

If we pass value  Paramere @ eid 1

As getemp 1

Then one record based on eid match

Hope this post helpful


If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website