Question

My Database stores the information of Students in a tables along with their course offerings in other tables. There are more associated tables.

Now I wanna create a form that looks like this : enter image description here

Depending on the search criterion, the Query shall be executed. More than one criterions may be selected. After hitting the search button, the various tupples shall be displayed.

Whats teasing me is how should i proceed with the Query part....???

Can anyone please help me out? b.t.w. I use SQL 2008R2 along with Visual Studio 2010.

Was it helpful?

Solution

If I understand what you want then you could use a stored procedure that looks something like this.

create procedure GetIT
  @Name varchar(10) = null,
  @AdminNo varchar(10) = null,
  @TickNo varchar(10) = null,
  @Course varchar(10) = null,
  @AcaYear varchar(10) = null
as

select T.YourColumnList
from YourTable as T
where  
  (T.Name    = @Name    or @Name    is null) and
  (T.AdminNo = @AdminNo or @AdminNo is null) and
  (T.TickNo  = @TickNo  or @TickNo  is null) and
  (T.Course  = @Course  or @Course  is null) and
  (T.AcaYear = @AcaYear or @AcaYear is null)

Depending on what radio buttons are selected you will pass a value or null as an argument.

Dynamic Search Conditions in T-SQL

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top