How would I implement the WHER clause of this SQL?
UPDATE address
SET add_current=True
WHERE (SELECT address_id, add_off_id, add_start_date FROM address as ATable
WHERE count (add_off_id) >1)
add_start_date is the newest date
IOW, I added the add_current field to my table because I found users were
lazily just putting any old start date in, so sorting by start date was
unreliable, so now I've forced a "current address" flag, but need to set as
many newest addresses to current using SQL as I can (of course, the
duplicate start dates will have to be done by hand).
--
Darryl Kerkeslager 5 2663
Darryl Kerkeslager wrote: How would I implement the WHER clause of this SQL?
UPDATE address SET add_current=True
WHERE (SELECT address_id, add_off_id, add_start_date FROM address as ATable WHERE count (add_off_id) >1) add_start_date is the newest date
IOW, I added the add_current field to my table because I found users were lazily just putting any old start date in, so sorting by start date was unreliable, so now I've forced a "current address" flag, but need to set as many newest addresses to current using SQL as I can (of course, the duplicate start dates will have to be done by hand).
I'm not entirely sure what you mean, but you could try something like
this:
SELECT TOP 1 address_id, add_off_id, add_start_date
FROM address
GROUP BY address_id, add_off_id, add_start_date
HAVING (count (address_id) >1)
ORDER BY add_start_date DESC;
HTH
Edward
> Darryl Kerkeslager wrote: How would I implement the WHER clause of this SQL?
UPDATE address SET add_current=True
WHERE (SELECT address_id, add_off_id, add_start_date FROM address as ATable WHERE count (add_off_id) >1) add_start_date is the newest date
IOW, I added the add_current field to my table because I found users were lazily just putting any old start date in, so sorting by start date was unreliable, so now I've forced a "current address" flag, but need to set as many newest addresses to current using SQL as I can (of course, the duplicate start dates will have to be done by hand).
<te********@hotmail.com> wrote I'm not entirely sure what you mean, but you could try something like this:
SELECT TOP 1 address_id, add_off_id, add_start_date FROM address GROUP BY address_id, add_off_id, add_start_date HAVING (count (address_id) >1) ORDER BY add_start_date DESC;
Running this query returns no records. The HAVING clause should be:
HAVING (count (add_off_id) >1)
but that also returns no records. This seems to be approximately what I
want (except I would turn it into an Update query to set the add_current
field to True), but again, this SQL does not return records.
--
Darryl Kerkeslager
> <te********@hotmail.com> wrote I'm not entirely sure what you mean, but you could try something like this:
SELECT TOP 1 address_id FROM address GROUP BY address_id, add_off_id, add_start_date HAVING (count (address_id) >1) ORDER BY add_start_date DESC;
Running this query returns no records. The HAVING clause should be:
HAVING (count (add_off_id) >1)
but that also returns no records. This seems to be approximately what I want (except I would turn it into an Update query to set the add_current field to True), but again, this SQL does not return records.
Well, I tested it in a table with some records that conformed to what I
think your table holds - e.g. multiple address IDs with differing
dates, and mine returned stacks of data.
Without access to your raw data, I suggest that you start from first
principles, and build up the SQL gradually. You know you want records
where the Count(add_off_id) > 1 so that's the place to start.
Incidentally, I assumed you'd realise that what I intended with my
SELECT was something like WARNING AIR CODE ALERT
UPDATE address
SET add_current=True
WHERE address_id IN (
SELECT TOP 1 address_id
FROM address
GROUP BY address_id, add_off_id, add_start_date
HAVING (count (address_id) >1)
ORDER BY add_start_date DESC)
HTH
Edward
I appreciate the time.
Perhaps I should explain my data, just in case - because I still can't get
it to return any records.
address_id (PK, autonumber)
add_off_id (FK, Long, has duplicates)
add_start_date (date, duplicate)
add_current (Boolean)
so sample data might be
1 256 1/1/2004 False
2 256 12/1/2005 False
3 480 1/1/2004 False
4 550 1/2/2005 False
5 980 4/7/2005 False
6 998 4/7/2005 False
7 998 4/9/2005 False
8 1200 1/1/2003 False
9 1230 1/1/2003 False
I want to set address_id #2 and #7 to True, because they have the same
add_off_id, and the add_start_date is the newest of the add_start_dates for
this add_off_id.
--
Darryl Kerkeslager
Well, not set the address_id to True obviously, but the add_current field
for those records.
--
Darryl Kerkeslager This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave |
last post by:
I have 2 tables, one with names, and another with addresses, joined by their
CIVICID number (unique to the ADDRESSINFO table) in Oracle.
I need to update a field in the NAMEINFO table for a...
|
by: Lauren Quantrell |
last post by:
In VBA, I constructed the following to update all records in
tblmyTable with each records in tblmyTableTEMP having the same
UniqueID:
UPDATE
tblMyTable RIGHT JOIN tblMyTableTEMP ON...
|
by: VK |
last post by:
<http://www.jibbering.com/faq/#FAQ3_2>
The parts where update, replacement
or add-on is needed are in <update> tag.
3.2 What online resources are available?
Javascript FAQ sites, please...
|
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums...
|
by: Shapper |
last post by:
Hello,
I have created 3 functions to insert, update and delete an Access
database record. The Insert and the Delete code are working fine.
The update is not. I checked and my database has all...
|
by: jaYPee |
last post by:
I have search a lot of thread in google newsgroup and read a lot of
articles but still i don't know how to update the dataset that has 3
tables.
my 3 tables looks like the 3 tables from...
|
by: PAUL |
last post by:
Hello,
I have 2 tables with a relationship set up in the dataset with vb
..net. I add a new record to the parent table then edit an existing child
record to have the new parent ID. However when I...
|
by: Zorpiedoman |
last post by:
I keep getting a concurrency exception the second time I make a change and
attempt to update a dataadapter. It appears this is by design, so there must
be something I can do to avoid it.
...
|
by: Stephen Plotnick |
last post by:
I'm very new to VB.NET 2003
Here is what I have accomplished:
MainSelectForm - Selects an item
In a public class I pass a DataViewRow to
ItemInformation1 Form
ItemInformation2 Form
|
by: Michel Esber |
last post by:
Hi all,
DB2 V8 LUW FP 15
There is a table T (ID varchar (24), ABC timestamp). ID is PK.
Our application needs to frequently update T with a new value for ABC.
update T set ABC=? where ID...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |