Access 2010 SQL Update cmd - sql

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;

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?

Multiple entries in crystal reportviewer after adding a SQL expression field

I am using Visual Studio 2017 and I installed the latest crystal reportviewer (22)
What I want is to click a button and create a report from the customer that is selected in the datagridview and the addresses that are shown in the second datagridview.
I managed to do all that but the problem is that a few fields contain numbers which need to be converted to text. An SQL query I would use to do this would be like:
SELECT c.customer_nr, c.status, s.rename FROM CUSTOMERS c INNER JOIN SETUP s on s.id = c.status WHERE s.afk = 'STA'
In my SETUP database I have the columns ID,AFK and RENAME so if the status would be 1 it would convert to text: "ACTIVE", if status = 2 it would convert to "INACTIVE" for example.
I could do something with a formula field like this:
IF ({c.status} = 1) THEN "ACTIVE" ELSE
IF ({c.status}) = 2 THEN "INACTIVE"
but that is not good because i could add another status or change the name in the database etc.
So then I tried with an SQL expression field and I put something like this:
(
SELECT "SETUP"."RENAME" FROM SETUP
WHERE "SETUP"."AFK" = 'STA' AND "SETUP"."ID" = "CUSTOMERS"."STATUS"
)
There must be something wrong because I get the correct conversion but there is only one address in the database but I get 7 pages all with the same address. There should only be one address like I get when I remove the SQL expression field. Where does it go wrong?
* EDIT *
I found the problem. When I create a new database that contains only unique id's then it works. In my original database I have multiple times the id's 1,2,3,4,5 but with different abbreviations in column AFK. Somehow the query looks for the id value and every time it finds this id no matter the AFK value it generates an entry for the address value.
Maybe in the future I will find out how this exactly works for now I have a workaround.
Create a new table for example CrRepSta and add the following entries:
ID,AFK,RENAME
1,STA,Active
2,STA,Inactive
etc
The new query:
(
SELECT "CrRepSta"."RENAME" FROM CrRepSta
WHERE "CrRepSta"."AFK" = 'STA' AND "CrRepSta"."ID" = "CUSTOMERS"."STATUS"
)
And by the way the statement "CrRepSta"."AFK" = 'STA' is not really needed.

ORA-00904 Invalid Identifier - Update Statement With Two Tables

I'm working with PeopleSoft Campus Solutions, and we need to update about 22,000 rows of data. This is data between the tables of ACAD_PLAN_VW and ACAD_PROG. Students are listed on both, so their IDs match between the two.
Basically what we are trying to do is say that when the ID, academic career, student career number, effective sequence, and effective date match, AND where the academic plan (their degree, as stored on the ACAD_PLAN_VW) is a specific value, update the ACAD_PROG on the ACAD_PROG table to X value.
I tried to do some very interesting combinations of FROM statements, constantly getting errors. After some researching, I found out that SQLTools doesn't really like FROM statements within UPDATE statements, so I rewrote it to just make the connections manually. I'm assuming I'm doing this right, unless I need to reword it.
The statement I have is:
UPDATE PS_ACAD_PROG SET PS_ACAD_PROG.ACAD_PROG = 'UGDS'
WHERE PS_ACAD_PLAN_VW.EMPLID = PS_ACAD_PROG.EMPLID
AND PS_ACAD_PLAN_VW.ACAD_CAREER = PS_ACAD_PROG.ACAD_CAREER
AND PS_ACAD_PLAN_VW.STDNT_CAR_NBR = PS_ACAD_PROG.STDNT_CAR_NBR
AND PS_ACAD_PLAN_VW.EFFSEQ = PS_ACAD_PROG.EFFSEQ
AND PS_ACAD_PLAN_VW.EFFDT = PS_ACAD_PROG.EFFDT
AND PS_ACAD_PLAN_VW.ACAD_PLAN = 'DSTDS'
Theoretically, I would assume that this would update any student who has those connections. However, the error that I'm currently getting is as follows:
ORA-00904: "PS_ACAD_PLAN_VW"."ACAD_PLAN": invalid identifier
I have, as of yet, been unable to figure out the issue. I do have the correct access to view and update those fields, and the field does indeed exist.
Oracle doesn't know it should use the PS_ACAD_PLAN_VW table. Somehow you should reference it.
For example can you try this way?
UPDATE (
select
PS_ACAD_PROG.ACAD_PROG,
PS_ACAD_PLAN_VW.ACAD_PLAN
from
PS_ACAD_PROG,
PS_ACAD_PLAN_VW
where
PS_ACAD_PLAN_VW.EMPLID = PS_ACAD_PROG.EMPLID
AND PS_ACAD_PLAN_VW.ACAD_CAREER = PS_ACAD_PROG.ACAD_CAREER
AND PS_ACAD_PLAN_VW.STDNT_CAR_NBR = PS_ACAD_PROG.STDNT_CAR_NBR
AND PS_ACAD_PLAN_VW.EFFSEQ = PS_ACAD_PROG.EFFSEQ
AND PS_ACAD_PLAN_VW.EFFDT = PS_ACAD_PROG.EFFDT
)
SET
ACAD_PROG = 'UGDS'
WHERE
ACAD_PLAN = 'DSTDS'
Try to use the table which is not getting identified,by keeping in where clause so that you can use the select statement.That will help identifying the tables.
The following implementation should work:
UPDATE PS_ACAD_PROG
SET ACAD_PROG = 'UGDS'
WHERE ROWID IN(SELECT PROG.ROWID
FROM PS_ACAD_PROG PROG
, PS_ACAD_PLAN_VW PLAN
WHERE PLAN.EMPLID = PROG.EMPLID
AND PLAN.ACAD_CAREER = PROG.ACAD_CAREER
AND PLAN.STDNT_CAR_NBR = PROG.STDNT_CAR_NBR
AND PLAN.EFFSEQ = PROG.EFFSEQ
AND PLAN.EFFDT = PROG.EFFDT
AND PLAN.ACAD_PLAN = 'DSTDS');

multi part identifier could not be bound sql

I get multipart can not be bound error on following query
update nfltx
set
b.boxno = a.boxno,
b.message = a.message,
b.nameboxno = a.nameboxno,
b.namemsg = a.namemsg,
b.phoneboxno = a.phoneboxno,
b.phonemsg = a.phonemsg
FROM ofltx a JOIN nfltx b
ON a.ls_fullnam = b.ls_fullnam
but if i remove b from boxno message and all i do not get the error . What is the reason behind this. Thank You using sql server 2008
A table alias specified in a FROM clause cannot be used as a qualifier in SET column_name. This is not valid:
update nfltx
set
b.boxno = a.boxno,
b.message = a.message,
b.nameboxno = a.nameboxno,
b.namemsg = a.namemsg,
b.phoneboxno = a.phoneboxno,
b.phonemsg = a.phonemsg
FROM ofltx a JOIN nfltx b
ON a.ls_fullnam = b.ls_fullnam
To make it work, remove the b. alias from the column name.
update nfltx
set
boxno = a.boxno,
message = a.message,
nameboxno = a.nameboxno,
namemsg = a.namemsg,
phoneboxno = a.phoneboxno,
phonemsg = a.phonemsg
FROM ofltx a JOIN nfltx b
ON a.ls_fullnam = b.ls_fullnam
Raj
What is the reason behind this?
An UPDATE (and DELETE, INSERT) can affect one, and only one, table. You've already identified which table you want to affect here:
update nfltx
Therefore, it doesn't make sense to allow an alias for the left hand side of assignments in the SET clause. They must be columns belonging to the previously identified table.
If the same table is included in the FROM clause multiple times (and it's the table you wish to update), you would need to provide an alias to indicate which instance of the table is to be updated - but you'd provide it (once) in the UPDATE clause rather than in the SET clause.
just use
update b
instead of
update nfltx
Man you guys make things too difficult for those that are learning.

running queries on more than one table

I'm trying to make a query in two tables:
SIMPLE_PERSON with 3 fields (name, grid and Social Security Card)
INDIVIDUAL_AGGREGATE with 4 fields: grid(PK), type( D(Driver) or C(client)), code, simple_person(foreign key of simple_person))
When I register some person, I have to save they on the SIMPLE_PERSON and set the type of aggregate that they are ( Driver or Client). And cannot have two equal social security card numbers.
With AJAX, I throw a checker that returns an alert box if the SSC is registered, but my SQL query doesn't work. I need to making a query that returns to me if a Social Security Card is already registered. I'm trying to use EXISTS, but I haven't had much success:
SELECT simple_person.name
FROM simple_person
WHERE SSC = 'SSC_NUMBER'
AND EXISTS (SELECT individual_aggregate.code FROM individual_aggregate
WHERE code = 'xx'
AND individual_aggregate.type = 'D');
Somebody can help me to make this query work?
did you wanted to check if there is a person that registered on a some Social security number?
if yes what i did is join between the two tables
and return the rows that equal to a specific social security number.
you can add to the WHERE statement (AND IA.code = 'XX' AND IA.Type = 'D')
SELECT SP.Name
FROM simple_person AS SP
INNER JOIN individual_aggregate AS IA ON SP.grid = IA.grid
WHERE SP.SSC = {someNumber}
helped you?
Your subquery in the EXISTS clause isn't actually hitting a table, view or other.
Your sub-select is missing the FROM clause.
SELECT
individual_aggregate.code
FROM
individual_aggregate
WHERE
code = 'xx'
AND individual_aggregate.type = 'D'
Regards
Sigersted