Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Selection Criteria (Where Clause in T-Sql)

Author  Topic 

dubaashu
Starting Member

10 Posts

Posted - 2014-05-11 : 23:48:57
Hi All,

I want a selection criteria to be

select * from @table Where field = ''

If select blank then display complete result and if selected some value then only that value display


thanks

Ashish



Ashish gupte

stepson
Aged Yak Warrior

545 Posts

Posted - 2014-05-12 : 01:09:25
[code]
WHERE Field = CASE @vcVar WHEN '' THEN Field
ELSE @vcVar END
[/code]


sabinWeb MCP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-05-12 : 07:20:32
use a parameter say @param through which you pass the value.
make query as below


select * from @table Where field = @param or @param = ''

it will make sure it selects all value when you pass '' to @param

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -