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 2000 Forums
 Transact-SQL (2000)
 View used inside if-else slows things

Author  Topic 

FileAnt
Starting Member

3 Posts

Posted - 2009-05-25 : 21:18:22
I used a huge view inside an 'if' recently and noticed it did short circuit; however, the query still slows down.

SET @ADate = NULL

IF (@ADate IS NOT NULL)
BEGIN
INSERT INTO #ABla VALUES (1) (
SELECT bla
FROM a huge VIEW
WHERE AColumn = 'poop')
END

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2009-05-25 : 23:12:53
Try to put an index on you're AColumn and to the referenced joins of you're huge view.



For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-25 : 23:25:44
quote:
Originally posted by FileAnt

I used a huge view inside an 'if' recently and noticed it did short circuit; however, the query still slows down.

SET @ADate = NULL

IF (@ADate IS NOT NULL)
BEGIN
INSERT INTO #ABla VALUES (1) (
SELECT bla
FROM a huge VIEW
WHERE AColumn = 'poop')
END


Which query is slow ? the huge view or you have other query that is not shown here.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -