Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have 2 tables in sql database with following details:
Table1:ID, Device, Category, Date,Company
Table2: ID,PersonName,Reason

In asp.net gridview im able to retreive data from 2 tables using JOIN in stored procedure. But i have to search data based on device and category for which im using 2 dropdown in gridview. it must display matched details from table2 as well. But how to write stored procedure for this? please help with complete stored procedure.
Posted
Updated 16-Apr-15 0:58am
v2
Comments
Maciej Los 15-Apr-15 11:08am    
What have you tried? Where are you stuck?
Member 11377180 16-Apr-15 7:00am    
I have improved question.ID is the column connecting 2 tables. right now i hav retreived data from both tables into single gridview. In same gridview i want to sort data based on device and category. im using dropdown for this .how to write stored procedure for this?
Deepak Kanswal Sharma 15-Apr-15 12:49pm    
How have you joined the two tables? Which columns are you comparing?
Member 11377180 16-Apr-15 7:00am    
I have improved question.ID is the column connecting 2 tables. right now i hav retreived data from both tables into single gridview. In same gridview i want to sort data based on device and category. im using dropdown for this .how to write stored procedure for this?

1 solution

Hi,

this stored procedure will if not put any parameter or giving single or both parameter. it is flexible to run by any condition.

Please arrange proper table join & select query based on your requirement because you did not provide the proper table structure.



SQL
create procedure search
@Device varchar(50)=NULL,
@@Category varchar(50)=NULL

as 

select t1.Device, t1.Category, t1.Date,t1.Company
t1.PersonName,t1.Reason
FROM table1 T1
JOIN table2 T2 ON T1.ID=t2.Id

WHERE Device=ISNULL(@Device,Device) AND Category=ISNULL(@Category,Category)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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