| Author |
Topic  |
|
|
pkuchaliya
Starting Member
India
49 Posts |
Posted - 09/05/2008 : 08:14:39
|
create table timepass(id varchar(50),age int, salary int,designation varchar(50),department varchar(50))
insert into timepass values('10001',24, 2500,'Manager','IT')
insert into timepass values('10002',24, 8900,'accountant','IT')
insert into timepass values('10003',24, 6500,'peon','admin')
insert into timepass values('10004',24, 8800,'developer','account')
insert into timepass values('10005',24, 14500,'sr. developer','hr')
insert into timepass values('10006',24, 9500,'programmer','IT')
hi i have write a procedure in i recieved four parameter
@age,@salary,@designation,@department
user can search on given parameter and it is not compulsory that he will give all the parameter to search. but if use want to search only on the basis of age , salary then it will search only given criteria and remainder parameter will assign to '0', and if he want to search all condition then it search all.
pankaj |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 09/05/2008 : 08:22:33
|
you don't need dynamic SQL
select *
from timepass
where (
@age is null
or age = @age
)
and (
@salary is null
or salary = @salary
)
. . . .
KH Time is always against us
|
 |
|
|
TG
Flowing Fount of Yak Knowledge
USA
5469 Posts |
Posted - 09/05/2008 : 08:23:50
|
make sure to validate that at least one parameter is passed has a value (unless you want to allow that all rows could be returned), then:
WHERE age = isNull(@age, age) AND salary = isNull(@salary, salary) AND desigination = isNull(@designation, designanation) etc...
Be One with the Optimizer TG |
 |
|
| |
Topic  |
|
|
|