Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Server 2005 script help

Posted on 2009-07-09
4
Medium Priority
?
175 Views
Last Modified: 2012-05-07
Hi,

I have 2 tables one holding customer data, the other holding referral data, now I need to update a field based upon the referrals and this needs to be done nightly, for example

CUSTOMER (Table called contact2)
ACCOUNTNO, ULASTPROP

REFERRAL (Table called contsupp)
ACCOUNTNO, RECTYPE, DATE

Now what I need to do is make the ULASTPROP field equal to the newest date in the referral table using the accountno as the matching field. So if I take my customer entry, I may have 4 linked entries in referral table but I need the ULASTPROP to match the date of the LATEST referral.

Now I need to run through the entire customer database (approx 160,000) every night on an automated script, but im a bit stuck on where to proceeded.
0
Comment
Question by:DJMikeh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 24815399
update t1
set ulastprop = max(t2.date)
from customer t1 inner join referral t2 on t1.accountno = t2.accountno
0
 

Author Comment

by:DJMikeh
ID: 24821383
UPDATE t1 SET t1.ulastpropa = max(t2.lastdate)
FROM contact2 t1
INNER JOIN contsupp t2 ON t1.accountno = t2.accountno
WHERE t2.rectype='R'

When running the script above I get

An aggregate may not appear in the set list of an UPDATE statement.

Ideas? ive tried with and without the WHERE clause and it's the same each time.
0
 

Accepted Solution

by:
DJMikeh earned 0 total points
ID: 24821948
I have solved it myself using

UPDATE contact2 SET ulastpropa = (SELECT max(lastdate) FROM contsupp WHERE contact2.accountno = contsupp.accountno AND rectype='R')
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question