Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

optimize sql statement

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
Avatar of JoeNuvo
JoeNuvo
Flag of Viet Nam image

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.
Avatar of bibi92

ASKER

7332245rows and 2345673rows
Thanks
Regards
bibi
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

ASKER CERTIFIED SOLUTION
Avatar of JoeNuvo
JoeNuvo
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bibi92

ASKER

Thanks bibi