Solved

optimize sql statement

Posted on 2011-03-15
5
288 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

808 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