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.
| Author |
Topic |
|
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2010-08-03 : 09:18:01
|
| Hi allI am not able to put the logic how to update the agent value for the respective acountsinvoice account agent11 1 vijay12 1 vikas13 2 ajay14 2 vijay15 2 vijayI want updated table in this mannerinvoice account agent11 1 vijay12 1 vijay13 2 ajay14 2 ajay15 2 ajay |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-08-03 : 10:39:21
|
| What is the logic to do the update? Should we choose the agent for the lesser invoice number for each account? |
 |
|
|
kashyap_sql
Posting Yak Master
174 Posts |
Posted - 2010-08-04 : 01:54:56
|
i think the logic must be like where invoice in('14','15')With RegardsKashyap M |
 |
|
|
kashyap_sql
Posting Yak Master
174 Posts |
Posted - 2010-08-04 : 02:19:47
|
| [code]UPDATE table_nameSET agent=ajayWHERE invoice in('14','15')[/code]try thisWith RegardsKashyap M |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-08-04 : 06:38:54
|
| [code]update t1 set t1.agent=t.agentfrom yourtable T1cross apply(select top 1 agent from yourtable t2 where t1.account=t2.account)T[/code]Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
|
|
|