asp.net - How to cater Search from front-end in SQL Server query -


i have asp.net application. functionality required is:

there 1 dropdown , gridview underneath. when page loaded first time, nothing selected in dropdown. query works like:

select * mytable; 

then when select dropdown, query is:

select * mytable col1 = @valueselected 

i want use single query both cases, i.e

select * mytable case @valueselected when null col1 in ('all', 'passed', 'failed') else col1 = @valueselected end 

or

select * mytable case @valueselected when not null col1 = @valueselected else null end 

but both dont work of now.

any help/suggestions/pointers ?

the syntax use used simulate if else condition using case statement in where clause wrong.

if need specific list of values col1 try this.

select *   mytable  ( col1 in ( 'all', 'passed', 'failed' )          , @valueselected null )         or col1 = @valueselected  

if want have values in col1 try this.

select * mytable col1 = coalesce(@valueselected,col1) 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -