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 2005 Forums
 Transact-SQL (2005)
 Is the logic right?

Author  Topic 

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2009-04-01 : 15:24:30
Hello,

I am going to update a column in a temp table.
Can you look at is it right?

exec('update #Tmp Data set REASON=
(select A.CODEDESC
FROM REASONCODES A join LOAN L
on L.REAS_CD= A.CODEID WHERE #TmpData.TRAN_TYPE = A.CODEGROUP)')


Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-04-01 : 15:27:50
Why are you using dynamic SQL for this? There is nothing dynamic about it!

I wouldn't use a subquery. I'd write it like this:

update t
set REASON=A.CODEDESC
from #tmpData t
INNER JOIN REASONCODES A
ON #t.TRAN_TYPE = A.CODEGROUP
join LOAN L
on L.REAS_CD= A.CODEID

See how it is no longer dynamic?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -