Solved

optimize sql statement

Posted on 2011-03-15
5
287 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
ID: 35143761
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
ID: 35152330
7332245rows and 2345673rows
Thanks
Regards
bibi
0
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 35153397
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
ID: 35153403
oops, some mistake

please change SET x = NULL

to SET [ZDOS_0] = NULL
0
 

Author Closing Comment

by:bibi92
ID: 35304727
Thanks bibi
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from 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

Suggested Solutions

Title # Comments Views Activity
MS SQL Delete Query 9 29
This query failed in sql 2014 5 29
SSRS 2012 r2 - Parm Drop Down has Date/Time 12 30
Create snapshot on MSSQL 2012 3 16
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

815 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

12 Experts available now in Live!

Get 1:1 Help Now