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 |
|
Standos424
Starting Member
3 Posts |
Posted - 2010-04-05 : 11:13:07
|
| Hi,i need help with query. I have two tables SKz and SKPPpol. I need update record in SKz from SKPPpol, but in SKPPpol i have to find last record. When i use this query in SQL server, query execute with error: Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.Can you help me?QUERY: UPDATE SKz SET ProdejDPH=SKPPpol.KcJednFROM SKz LEFT JOIN SKPPpol ON SKz.ID=SKPPpol.RefSKzWHERE SKz.ID IN (select max(datcreate), RefSKz from SKPPpol where RefSKz in (select RefSKz from SKPPpol group by RefSKz having count(*)>=2) group by RefSKz)thank you very much |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-05 : 11:20:38
|
| what do you mean by last record? can you show a data sample from tables and explain?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-05 : 11:34:50
|
In this case the example code shows that datcreate should give the last record for each identical RefSKz.So you can try this:UPDATE SKz SET ProdejDPH=dt.KcJednFROM SKzJOIN(SELECT RefSKz, ROW_NUMBER() OVER (PARTITION BY RefSKz ORDER BY datcreate DESC) as rownum, KcJednFROM SKPPpol) AS dtON SKz.ID=dt.RefSKz AND dt.rownum=1 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Standos424
Starting Member
3 Posts |
Posted - 2010-04-06 : 10:14:02
|
| it´s great...thx |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-06 : 10:34:51
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|