Trouble Updating Field on a Particular Row - sql

I am trying to update a record in a particular existing row of data.
EX: Existing Output; Team, Year, Player, Position
LA Lakers 2016 Jim Bowen
Can someone provide me a sample of the code to update 'Position' column
Update LAL_Player_Stats
Set POSITION = C
Where Player = 'Bowen'
This returns: (0 row(s) affected)

You may have to try Player = 'Jim Bowen'.
Position should not be all caps.
Also, you need single-quotes on the "C": Set Position = 'C'.
Making your final statement:
Update LAL_Plater_Stats
Set Position = 'C'
Where Player = 'Jim Bowen'

Update LAL_Player_Stats SET position = 'C' WHERE player = 'Jim Bowen'
In the future, why not provide us the whole table so we can determine what you're missing when you update a row. It might help us more. :)

Related

Oracle Apex update specific row of table

Hi i want to update a specific row of my oracle database via apex. So i need to reach/address the specific row via where clause.
example entries:
GATTUNG
ART
UNTERART
ABART
VARIETÄT
AAA
AAA
AAA
NULL
NULL
AAA
AAA
NULL
NULL
AAA
AAA
AAA
NULL
NULL
NULL
Now i have two approaches.
first:
UPDATE TBL_PFLANZE
SET NAMEN =:P1_NAMEN
WHERE (GATTUNG = :P1_GATTUNG AND ART = :P1_ART_KREUZUNG)
AND ((UNTERART=:P1_UNTERART OR :P1_UNTERART IS NULL) AND (VARIETÄT=:P1_VARIETAET OR :P1_VARIETAET IS NULL) AND (ABART=:P1_ABART OR :P1_ABART IS NULL));
second:
UPDATE TBL_PFLANZE
SET NAMEN ='&P1_NAMEN.'
WHERE (GATTUNG = '&P1_GATTUNG.' AND ART = '&P1_ART_KREUZUNG.')
AND (UNTERART &P1_WHERE_UNTERART. AND VARIETÄT &P1_WHERE_VARIETAET. AND ABART &P1_WHERE_ABART.);
the differences of both approaches are the P1_WHERE_...variables.
the first one use for example :P1_UNTERART and contains the whole value
the second one use for example &P1_WHERE_UNTERART. and contains = '&P1_UNTERART.' OR IS NULL
my problem is:
the first one updates all entries if i only set GATTUNG and ART (if i do not specify one of the other variables)
the second will work, but is not the right approach as I should be using binding variables instead of &VAR.
So my question is, how can i use the first approach which the desired result... :(
Does this do the trick ? It will update the rows if any of the columns have the same value as the corresponding page item or the database column and page item are both null:
UPDATE tbl_pflanze
SET
namen = :P1_NAMEN
WHERE
( gattung = :P1_GATTUNG AND art = :P1_ART_KREUZUNG)
AND
( ( NVL(unterart,'X') = NVL(:P1_UNTERART,'X')) AND
( NVL(varietät,'X') = NVL(:P1_VARIETAET,'X')) AND
( NVL(abart,'X') = NVL(:P1_ABART,'X')) );
The way I see it, the 1st query is correct while the 2nd is wrong.
Why is it wrong? Because you're using strings. This:
SET NAMEN ='&P1_NAMEN.'
WHERE (GATTUNG = '&P1_GATTUNG.'
would want to put litally &P1_NAMEN. string into the NAMEN column for all rows whose GATTUNG column contains literally &P1_GATTUNG. string in it (and there's most probably none, so the 2nd query won't do anything, ever).
So, what is your problem, exactly? Why do you think that the 1st query doesn't work? Did you run the page in debug mode and reviewed debug results? Could it be that P1 page's items aren't stored into session state so UPDATE statement doesn't see them?
Also, where do you execute that UPDATE? As a process which runs after button is pressed? Something else?

populating field in access 2007 based on another field

I have data for tennis. I have two tables,(game_atp(Player 1, player 2, Name_T, surface) and tours_atp(ID, tournament, court surface)). In games_atp table i want to create a field surface and put the surface based on the tournament its played in( so based on Name_T), getting the info from tours_atp table.
thank you
Do you have a way to connect a row in game_atp to a row in tours_atp? For instance, is tours_atp.ID the same as game_atp.Name_T? There has to be a way to connect them. Also am I assuming that surface will be equal to whatever is in court surface? Assuming that tours_atp.ID is the same as game_atp.Name_T then you can just do...
UPDATE game_atp Set surface = (SELECT court_surface FROM tours_atp WHERE tours_atp.ID = game_atp.NAME_T)
This code will update all rows. If you want to update only a specific game then you will have to use a WHERE clause and tell it the id of the game like so...
UPDATE game_atp Set surface = (SELECT court_surface FROM tours_atp WHERE tours_atp.ID = game_atp.NAME_T ) WHERE game_atp.Name_T = '5555'

Access 2010 SQL Update cmd

I'm having some difficulty with an Update statement.
UPDATE DownPeriod
SET
DownPeriod.EquipmentID = ? ?? ?? ? ?? ?? ? ?,
DownPeriod.DownDate = Forms!Edit!EditDownDateBox,
DownPeriod.DownTime = Forms!Edit!EditDownTimeBox,
DownPeriod.[UpDate] = Forms!Edit!EditUpDateBox,
DownPeriod.UpTime = Forms!Edit!EditUpTimeBox,
DownPeriod.isScheduled = Forms!Edit!EditSchedCheck,
DownPeriod.isUnscheduled = Forms!Edit!EditUnschedCheck,
DownPeriod.Comments = Forms!Edit!EditCommentsDropDown
WHERE DownPeriod.DownPeriodID =Forms!Edit!RecordHistorySubform.Form!DownPeriodID;
Where the question marks are is where im having difficulty, and am not sure what to put.
Everything else about the update will work if I remove that statement so I know im on the right track. The difference with the EquipmentID is that I'm getting this value based on an input for another table entry. To elaborate the user chooses an Equipment Title, which is another field in my Equip Table that will relate to a unique ID.
So far I have tried DLOOKUP("[EquipmentID]", "Equipment", "[Title] = Forms!Edit!EditEquipmentDropDown")
Select statment and
using inner join
I'm at a loss and need help plz!
Thank you!
You say that the user is selecting the title from a dropdown. The dropdown should have a row source on these lines:
SELECT ID, Title FROM Equipment
With ID as a hidden column. Your update should then be:
DownPeriod.EquipmentID = Forms!Edit!EditTitleDropDown
As an aside, I suspect you are doing a lot more work that you need to do to make an MS Access form work.
If it is a new unique id you need an INSERT. If it already exists you should include it as part of your WHERE clause.
WHERE DownPeriod.DownPeriodID =Forms!Edit!RecordHistorySubform.Form!DownPeriodID
AND DownPeriod.EquipmentID = Forms!Edit!EditEquipmentDropDown;

sql - Possible to update two rows with different critera in one query?

This is for SqlCe,
I am trying to update a table and set won +=1 for a winner, and lost =1 for the loser.
I know I can do this with two different update statements but I was wondering if I could make update the winners "won" value at the same time that I update the losers "lost" value.
Basically just looking like this,
UPDATE player SET won = won +1 WHERE id = 0
UPDATE player SET won = lost +1 WHERE id = 1
This isn't pretty but it works
UPDATE player SET won = won + CASE WHEN id = 0 THEN -1 ELSE 1 END WHERE id in (0,1)
I'd personally stick with the two update statements

UPDATE SQL based on 2 conditions

Given the following table structure
Locations
LocationName|Easting|Northing
Incidents
LocationString|Easting|Northing|LocationName
LocationString is a badly formatted Subway Station Name that the user of the application can type any old rubbish in to. The eastings and Northings (Co-ordinates) are consistent however. Using them i can give the location a consistent name by looking those values up in a look up table.
In ACCESS SQL i would do the following
UPDATE INCIDENTS, Locations
SET Incidents.LocationName = Locations.LocationsName
WHERE Incidents.Easting = Locations.Easting
AND
Incidents.Northing = Locations.Northing
How do i accomplish the same in T-SQL?
UPDATE I
SET I.LocationName = L.LocationsName
FROM Incidents I
JOIN Locations L
ON I.Easting = L.Easting AND I.Northing = L.Northing