开发者

Dynamic Query from GUI

开发者 https://www.devze.com 2023-03-29 08:37 出处:网络
My Database stores the information of Students in a tables along with their course offerings in other tables. There are more associated tables.

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 :

Dynamic Query  from GUI

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 Que开发者_JAVA技巧ry part....???

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号