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 2012 Forums
 Transact-SQL (2012)
 Error in If EXISTS

Author  Topic 

samir.first
Starting Member

34 Posts

Posted - 2014-06-11 : 05:55:52
when i used select statement with if Exists the query is very very slow
and takes 10 min
and when i used the query without if exists clause it runs instantly
if exists (select null from table)
select 1
else
select 0
==================================
select null from table

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2014-06-11 : 06:40:33
Where is the error?
Where is the question?
Where is the sense of "select null from table"?

I really don't know how to help you, can you make it more clear please? :)


Too old to Rock'n'Roll too young to die.
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2014-06-11 : 12:17:34
Why are you using if exists here no need...

Select *
From [dbo].[YourTable]
Where [ColumnName] is null
Or [ColumnName] = ''

We are the creators of our own reality!
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2014-06-11 : 12:30:56
Try this:

With findnulls
as
(
Select
WithNulls = Case
When yourcolumn Is Null OR yourcolumn = ''
Then 1 else 0
End

From [dbo].[yourtable]
)
Select
Sum(WithNulls) 'TotalNulls'
From findnulls

We are the creators of our own reality!
Go to Top of Page
   

- Advertisement -