Solved

optimize sql statement

Posted on 2011-03-15
5
285 Views
Last Modified: 2012-05-11
Hello,

How can I optimize this statement which takes time :

select *   ,
(
select name
from [server].base.sys.schemas
where name = 'TESTS' and rowid not in (select ZROWID_0 from  ods.schema.table where [ZDOS_0] = 'TEST')

) as [ZDOS_0] into #stmt_repl
from [server].base.schema.table

Thanks

bibi
0
Comment
Question by:bibi92
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:JoeNuvo
Comment Utility
How many rows return from each table?

SELECT COUNT(*) FROM [server].base.sys.schemas WHERE name = 'TESTS'
SELECT COUNT(*) FROM ods.schema.table WHERE [ZDOS_0] = 'TEST'

Since I'm wonder why it will take some significant process time.
0
 

Author Comment

by:bibi92
Comment Utility
7332245rows and 2345673rows
Thanks
Regards
bibi
0
 
LVL 11

Expert Comment

by:JoeNuvo
Comment Utility
Not sure if this will help

DECLARE @name sysname -- change datatype if need to
SELECT @name = name FROM [server].base.sys.schemas WHERE name = 'TESTS'

SELECT *, @name as [ZDOS_0]
INTO #stmt_repl
FROM [server].base.schema.table

UPDATE #stmt_repl
SET x = NULL
FROM ods.schema.table OST
WHERE #stmt_repl.rowid = OST.ZROWID_0 -- if field name is not rowid, change it to the correct one
AND OST.ro = 'TEST'

Open in new window

0
 
LVL 11

Accepted Solution

by:
JoeNuvo earned 500 total points
Comment Utility
oops, some mistake

please change SET x = NULL

to SET [ZDOS_0] = NULL
0
 

Author Closing Comment

by:bibi92
Comment Utility
Thanks bibi
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now