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
 whats wrong with this update statement?

Author  Topic 

kifeda
Posting Yak Master

136 Posts

Posted - 2007-12-21 : 16:25:02
I wrote this update statement and it looks right but I keep getting an error that says "incorrect syntax next to c" what did I do wrong?

Here is the statement:

UPDATE tblclients c
SET intproviderId = (SELECT TOP 1 t.inttransferid FROM tbltransfer t WHERE t.intclientids = c.intclientid ORDER BY t.inttransferid DESC)

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-12-21 : 17:00:39
try this:


UPDATE c
SET intproviderId = (SELECT TOP 1 t.inttransferid FROM tbltransfer t WHERE t.intclientids = c.intclientid ORDER BY t.inttransferid DESC)
from tblclients c



elsasoft.org
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-22 : 01:06:39
or this:-

UPDATE c
SET c.intproviderId = tmp.inttransferid
from tblclients c
CROSS APPLY
(SELECT TOP 1 t.inttransferid
FROM tbltransfer t
WHERE t.intclientids = c.intclientid
ORDER BY t.inttransferid DESC)tmp
Go to Top of Page

kifeda
Posting Yak Master

136 Posts

Posted - 2008-03-06 : 14:42:23
I tried the last statement and it looks like ms sql server doesn't like cross apply
Go to Top of Page

JasonL
Starting Member

35 Posts

Posted - 2008-03-06 : 16:11:53
UPDATE c
SET intproviderId = (SELECT min(t.inttransferid) FROM tbltransfer t WHERE t.intclientids = c.intclientid))
from tblclients c

This may work?

JasonL
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-07 : 03:26:21
quote:
Originally posted by kifeda

I tried the last statement and it looks like ms sql server doesn't like cross apply


Did you try jazemine's query also?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-07 : 04:13:02
quote:
Originally posted by kifeda

I tried the last statement and it looks like ms sql server doesn't like cross apply


CROSS APPLY requires SQL 2005 with compatability level set to 90
Go to Top of Page
   

- Advertisement -