?
Solved

Query

Posted on 2011-10-12
9
Medium Priority
?
178 Views
Last Modified: 2012-05-12
Hi ,
How can I cahnge in the below to one query.
Thanks

If (@T<>'')
Begin
Select *  from tabl1  where T1=@T
end
else
begin
Select *  from tabl1
end
0
Comment
Question by:samprg
  • 4
  • 3
  • 2
9 Comments
 
LVL 41

Expert Comment

by:ralmada
ID: 36957956
Select *  from tabl1  where T1=@T or @T is null



0
 
LVL 41

Expert Comment

by:ralmada
ID: 36957964
or if you have @T ='' (but not null)

Select *  from tabl1  where T1=@T or @T = ''
0
 
LVL 41

Accepted Solution

by:
ralmada earned 2000 total points
ID: 36957978
if you want to consider both '' and nulls then

Select *  from tabl1  where T1=@T or isnull(@T,'') = ''
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 8

Expert Comment

by:Crashman
ID: 36958011
Select *  from tabl1  where (@T is null or T1=@T)
or
Select *  from tabl1  where (@T <> '' or T1=@T)
0
 

Author Closing Comment

by:samprg
ID: 36958067
Awesome
0
 

Author Comment

by:samprg
ID: 36958073
Crashman:
Sorry I did not read you comment
0
 
LVL 41

Expert Comment

by:ralmada
ID: 36958080
Crashman comment was wrong anyway :) second query should have been:

Select *  from tabl1  where (@T = '' or T1=@T)

not

Select *  from tabl1  where (@T <> '' or T1=@T)

0
 
LVL 8

Expert Comment

by:Crashman
ID: 36958082
it's ok, the importa is you resolve you question
0
 

Author Comment

by:samprg
ID: 36958096
Crashman:
Thank you
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question