473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Updating the first row which is null

Hello

I am trying to update table1 and set a new value with a condition
selecting only the results for the element with the specified ID and
the first one with the Date field null.
The query executes but it doesn t not update the informations. I ve
tried using TOP 1 and spent hours on this query but i can t get it to
work.

UPDATE table1 SET table1.Name = newName
WHERE table1.Date = (SELECT First(table1.Date) FROM table1 WHERE
table1.Date = Null And table1.ID = specifiedID);;

thank you for your help

Updating the first row which is null

Apr 8 '06 #1
6 4290
you can use the TOP predicate in a query (and presumably in a subquery,
though i've never tried it), if you also include an ORDER BY clause. the
records have to be in a specified order, so that Access can figure out which
record is the TOP 1.

hth
<re***********@yahoo.fr> wrote in message
news:11*********************@e56g2000cwe.googlegro ups.com...
Hello

I am trying to update table1 and set a new value with a condition
selecting only the results for the element with the specified ID and
the first one with the Date field null.
The query executes but it doesn t not update the informations. I ve
tried using TOP 1 and spent hours on this query but i can t get it to
work.

UPDATE table1 SET table1.Name = newName
WHERE table1.Date = (SELECT First(table1.Date) FROM table1 WHERE
table1.Date = Null And table1.ID = specifiedID);;

thank you for your help

Updating the first row which is null

Apr 8 '06 #2
I tried this but I get an error with this one

UPDATE table1 SET table1.Name = setName
WHERE table1.Date = (SELECT TOP 1 table1.Date FROM table1
WHERE isNull([table1.Date]) = true And table1.ID = specifiedID
ORDER BY DateValue(table1.Date) ASC);

I also tried this but it doesn t update any row

UPDATE table1 SET table1.Name = setName
WHERE table1.ID = specifiedID And table1.Date = (SELECT TOP 1
table1.Date FROM table1
WHERE isNull([table1.Date]) = true);

Any ones has got an idea?

Apr 8 '06 #3
"re***********@yahoo.fr" <re***********@yahoo.fr> wrote in
news:11*********************@e56g2000cwe.googlegro ups.com:
Hello

I am trying to update table1 and set a new value with a
condition selecting only the results for the element with the
specified ID and the first one with the Date field null.
The query executes but it doesn t not update the informations.
I ve tried using TOP 1 and spent hours on this query but i can
t get it to work.

UPDATE table1 SET table1.Name = newName
WHERE table1.Date = (SELECT First(table1.Date) FROM table1
WHERE table1.Date = Null And table1.ID = specifiedID);;

thank you for your help

Updating the first row which is null


If table1.date is null, then WHERE table1.Date = (SELECT ....
will never be true, and will not return any recoords.

try
SELECT TOP 1 Date FROM Table1
WHERE table1.Date = Null
AND table1.ID = specifiedID
;
as a query, and use that query in the update

UPDATE table1
SET table1.Name = newName
FROM query1
;

When the two queries work correctly, you can optionally merge
them to get something like

UPDATE table1
SET table1.Name = newName
FROM (SELECT TOP 1 Date FROM Table1
WHERE table1.Date = Null
AND table1.ID = specifiedID
)
;

--
Bob Quintal

PA is y I've altered my email address.
Apr 8 '06 #4
Bob Quintal <rq******@sympatico.ca> wrote in
news:Xn**********************@207.35.177.135:
See my fix, I had an = instead of an IS, which will always be
false.
"re***********@yahoo.fr" <re***********@yahoo.fr> wrote in
news:11*********************@e56g2000cwe.googlegro ups.com:
Hello

I am trying to update table1 and set a new value with a
condition selecting only the results for the element with the
specified ID and the first one with the Date field null.
The query executes but it doesn t not update the
informations. I ve tried using TOP 1 and spent hours on this
query but i can t get it to work.

UPDATE table1 SET table1.Name = newName
WHERE table1.Date = (SELECT First(table1.Date) FROM table1
WHERE table1.Date = Null And table1.ID = specifiedID);;

thank you for your help

Updating the first row which is null


If table1.date is null, then WHERE table1.Date = (SELECT ....
will never be true, and will not return any recoords.

try

SELECT TOP 1 Date FROM Table1
WHERE table1.Date IS Null
AND table1.ID = specifiedID
;

as a query, and use that query in the update

UPDATE table1
SET table1.Name = newName
FROM query1
;

When the two queries work correctly, you can optionally merge
them to get something like

UPDATE table1
SET table1.Name = newName
FROM (SELECT TOP 1 Date FROM Table1
WHERE table1.Date IS Null
AND table1.ID = specifiedID
)
;


--
Bob Quintal

PA is y I've altered my email address.
Apr 8 '06 #5
In your (Select top 1) query, your WHERE clause is limiting your results to
only those records where there is no date.
In other words, you're looking through dateless records to find the most
recent one. It's impossible.

When you say "the first one with the Date field null", you're going to have
to find some other way to determine the "first one" since you obviously
can't use the date field to do that.

<re***********@yahoo.fr> wrote in message
news:11*********************@e56g2000cwe.googlegro ups.com...
Hello

I am trying to update table1 and set a new value with a condition
selecting only the results for the element with the specified ID and
the first one with the Date field null.
The query executes but it doesn t not update the informations. I ve
tried using TOP 1 and spent hours on this query but i can t get it to
work.

UPDATE table1 SET table1.Name = newName
WHERE table1.Date = (SELECT First(table1.Date) FROM table1 WHERE
table1.Date = Null And table1.ID = specifiedID);;

thank you for your help

Updating the first row which is null

Apr 8 '06 #6
Hey guys thx a lot for yur help
I manage to get it working starting from the subquery which was
incorrect

UPDATE table1 SET table1.Name = setName
WHERE table1.Code = (SELECT TOP 1 table1.Barcode AS Code FROM table1
WHERE table1.ID=specifiedID And table1.Date IS NULL ORDER BY
table1.Code;);

Apr 8 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to...
1
by: Chris Jackson | last post by:
I'm a novice Access user and am not sure how to solve the following problem. Any help with the following would be greatly appreciated! I have two tables with identical structures, the first holds...
1
by: Luis Esteban Valencia | last post by:
Hello Everyone, Iam an intermediate ASP.Net programmer and iam facing a challenging task. I have a table in MS-SQL server database called 'Members'. The table has following fields... ...
5
by: Ryan Ternier | last post by:
I'm having an issue with an SQL insert statement. It's a very simple statement, and it's causing too much fuss. strSQL = "INSERT INTO tblFieldLayouts(TypeID, FieldID, OrderID, Hidden) VALUES("...
5
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I...
6
by: Hevan | last post by:
Hi, I am using this sql for updating a large table. This sql should update a record like 'abc123'. The first select will return 'abc' and the second select will return '123'. This works fine...
4
by: directory | last post by:
hey guys, I've got a weird one for ya....i have a form which takes user input in the form of textbox's etc. It then grabs some details from a file and updates some of the labels with some info...
0
by: preeti13 | last post by:
i have a two tables employeenominations and reason if someone storing a data first time it will store into the employeenominations table if name is already exist it will store into the reason table...
2
by: alnoir | last post by:
I'm trying to update some records using the UPDATE and SELECT query. I have two databases. The first database (db1) is a subset of the second database (db2). However, the first database is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.