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)
 optimization problem

Author  Topic 

linda9898
Starting Member

28 Posts

Posted - 2007-10-01 : 17:03:33
Hi all,

i have an SP with a nasty select that take me alot of time as i need to do it twice as follow

Update table1
Set col1 = select x from table2

Update table1
Set col2 = select y from table2

is there any possible that i will do it with only one select or one set instead of twice as this is realy a nasty select qry which take alot of time.

thanks,
Linda.

Kristen
Test

22859 Posts

Posted - 2007-10-01 : 17:20:55
Probably need to see the "nasty select" in full, because I doubt you can be doing

Update table1
Set col1 = select x from table2

as that would, presumably, try to set "col1" to multiple rows from table2.

Guessing:

You might be able to do something like:

UPDATE U
SET col1 = T2.foo,
col2 = T2.bar
FROM Table1 AS U
JOIN Table2 as T2
ON T2.ID = U.ID

possible with some CASE stuff or a Nested-Aggregating-Sub-select

Kristen
Go to Top of Page

linda9898
Starting Member

28 Posts

Posted - 2007-10-02 : 04:51:22
hi kristen, thanks again ...
Go to Top of Page
   

- Advertisement -