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
 General SQL Server Forums
 New to SQL Server Programming
 update Query with Order by Clause- SQL Server2008

Author  Topic 

paramu
Posting Yak Master

151 Posts

Posted - 2010-01-12 : 03:28:36
Hi,
I have a update query, But need with Order by Clause.
I cannot identify the error....

update sales_master set un_rate = (select qtnmaster.un_rate where qtnmaster.itemcode=sales_master.itemcode order by (0+qtnmaster.Qtnno))

Thanks For The Ideas...


Paramu @ PARANTHAMAN

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-12 : 03:30:53
[code]update s
set s.un_rate=q.un_rate
from sales_master s
cross apply (select top 1 un_rate from qtnmaster where itemcode=sales_master.itemcode order by (0+Qtnno))q[/code]
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-01-12 : 04:09:22
"update sales_master set un_rate = (select qtnmaster.un_rate where qtnmaster.itemcode=sales_master.itemcode order by (0+qtnmaster.Qtnno))"

Isn't that trying to set each row in [sales_master] to every row in [un_rate] just to try to get the "last" row?

Could you change the Sub Select to SELECT TOP 1 and change the ORDER BY to be DESCending?


Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2010-01-12 : 06:22:15
Great.!!!
Thanks For The Wonderful Tips !!! [Both]

After adding DESC to Visakh's ideas, I found the required O/P.
Thanks Again..To Both Ideas.!!!

Paramu @ PARANTHAMAN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-12 : 06:49:05
welcome
Go to Top of Page
   

- Advertisement -