How would I implement the WHER clause of this SQL?
UPDATE address
SET add_current=Tru e
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 2680
Darryl Kerkeslager wrote: How would I implement the WHER clause of this SQL?
UPDATE address SET add_current=Tru e
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=Tru e
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********@hot mail.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********@hot mail.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_i d) > 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=Tru e
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 particular surname in a
particular town.
I can select the records fine with this syntax (testing in Oracle SQL* Plus)
SELECT NAMEINFO.LASTNAME, NAMEINFO.FIRSTNAME, NAMEINFO.MIDDLENAME,
NAMEINFO.GENDER, ADDRESSINFO.REGION FROM NAMEINFO, ADDRESSINFO...
|
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 tblMyTable.UniqueID =
tblMyTableTEMP.UniqueID
SET
tblMyTable.myField = tblMyTableTEMP.myField,
tblMyTable.myField2 = tblMyTableTEMP.myField2,
|
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 check these first:-
<http://developer.irt.org/script/script.htm>
|
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 must be UPDATED, if not, they
must be INSERTED.
Logically then, I would like to SELECT * FROM <TABLE>
WHERE ....<Values entered here>, and then IF FOUND
UPDATE <TABLE> SET .... <Values entered here> ELSE
INSERT INTO <TABLE> VALUES <Values...
|
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 the necessary
records in it when testing it. I get the error "No value given for one
or more required parameters." when I try to update the database.
Can you tell me what am I doing wrong?
| |
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 northwind database that has
an employees, orders, and order details.
the following are the 3 tables in my sql database
students
schyrsem
|
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 do the update the changed
parentid in the child table fails to change. No error is given its just that
the change is not written to the Database.
When I step through the records for the child table the one I would expect
to be changed has a row...
|
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.
Example:
I have a dataadapter that contains one table with one row. I change the
value of the 'FisrtName' column in that row from Jack to John. I call
..update on the dataadapter it goes through fine. Now I change that same
column in that same row...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |