Can I make the determination of which column I update conditional on something? - sql-update

Is it at all possible to make the determination of which columns to update in an update statement conditional?
I am trying to run an update query to update one of 30 columns per record, but only if the previous field in the record is already filled in. Basically I have a table with projects and a table with donors. Each project has 1 to 4 donors, but each donor has funded between 1 and 25 projects. The projects page is filled in with donors, and so I am trying to automatically fill in the donors with projects they have funded. So far my attempt is as follows. (The query from which I am updating is a query that selects fields when the donors from the donor table equal donor 1 or donor 2 or donor 3 or donor 4 from the project table) :
UPDATE [Appropriate Query]
SET (iif([Project Funded 1 title] is null OR [project funded 1 title] <>
[Project title], [project funded 1 title], iif([project funded 2 title]
is null OR [project funded 1 title] <> [Project title], [project funded 2 title]))
= Iif([Project title] is null, [cc number], [project title])
(i have this nested loop first SET part looped for 30 columns. the second part of my code is because some of the "project title" fields are empty but I need some identifier in the field)
So far I have only gotten error messages. Is it at all possible to make the determination of which columns to update conditional on their contents as illustrated above? I know the iif statement is ugly, but JET SQL (the language of access) doesn't allow case statements, from what I understand.
Thank you so much, and forgive my ignorance.

You can't, except by building the SQL dynamically with VBA.
BUT you shouldn't do that (at least not here), instead you should correct your table design.
You have a many-to-many relationship between projects and donors, so you should have a Junction table between them, instead of multiple columns in the base tables.
Edit
Sure, with a series of INSERT queries, e.g. if you have filled the projects table:
INSERT INTO junction (project_id, donor_id)
SELECT id, donor1 FROM project WHERE donor1 IS NOT NULL;
INSERT INTO junction (project_id, donor_id)
SELECT id, donor2 FROM project WHERE donor2 IS NOT NULL;
etc.

Related

Oracle Apex 22.21 - Chart Page - Bar Type - Datepicker - How to update the source query to include a count and group by day

This question is a follow up to another SO question
I want a bar chart to show the amount of orders in a given date or range. Koen's updated answer shows:
'The "Value" is the amount of orders on each day. Update your source query to include a count of the orders and group by day. Then make your value attribute the column that has the count.'
How would I go about doing this?
Summary: I have a table ORDERS which contains column ORDER_DATE. I have created a Chart as a Bar type. I want the chart to show the amount of orders in a given date or range.
I'm following this Youtube tutorial which shows how to create a datepicker that returns a range in a Report. I'm trying to replicate this in a chart.
What I've done so far
Created datepicker items P5_DATE_FROM and P5_DATE_TO
Changed the Series Source Type to SQL Query
select ORDER_ID,
ORDER_NUMBER,
ORDER_DATE,
STORE_ID,
FULL_NAME,
EMAIL,
CITY,
STATE,
ZIP_CODE,
CREDIT_CARD,
ORDER_ITEMS,
APEX$SYNC_STEP_STATIC_ID,
APEX$ROW_SYNC_TIMESTAMP
from ORDERS_LOCAL
where ORDER_DATE between TO_DATE(:P5_DATE_FROM,'YYYY-MM-DD') and TO_DATE(:P5_DATE_TO,'YYYY-MM-DD')
Source Page Items to Submit added P5_DATE_FROM,P5_DATE_TO
I basically followed the exact steps of the video.
However, on the Page Designer I cannot save and run page until I select Column Mapping - Label and Value. I've set the Label as ORDER_DATE but I am unsure of what to select for the Value.
Setting the Value to ORDER_DATE shows an error Ajax call returned server error ORA-01403: no data found for CHART Count Orders by Date.
and selecting any other Value such as ORDER_NUMBER or ZIP_CODE populates the chart with the actual integer value of the column (ex: ZIP_CODE returns a chart of x-axis: date, y-axis: actual zip code numbers)
-----------UPDATE----------
Per Koen's answer, I've updated the Source SQL Query to below but I am now receiving an error.
And if I copy the exact query that Koen suggested, I run into below:
I did some messing around and found if I include APEX$SYNC_STEP_STATIC_ID and APEX$ROW_SYNC_TIMESTAMP the missing expression error goes away but instead I receive the GROUP BY error.
Something like this (untested) should work. Use TRUNC to ensure all orders on the same date are grouped (since date has a time portion, you'd have a different column for each different date time. Use ORDER_DATE as label and ORDER_COUNT as value.
select COUNT(ORDER_ID) AS ORDER_COUNT,
TRUNC(ORDER_DATE) AS ORDER_DATE,
from ORDERS_LOCAL
where ORDER_DATE between TO_DATE(:P5_DATE_FROM,'YYYY-MM-DD') and TO_DATE(:P5_DATE_TO,'YYYY-MM-DD')
GROUP BY TRUNC(ORDER_DATE)

How do I collapse an expanded column into single rows?

I have a SharePoint list containing a column with data type People or Group which can contain multiple people. When this list is imported into Power BI it appears as [Table] in the Power BI Query Editor.
When I expand this column (using highlighted button above), it creates multiple rows (which I don't want).
My goal is to preserve the row count of my table by converting all duplicate rows created by the expansion back to single rows with a delimiter between values. Has anyone found a way to consolidate this?
Data example
Original Data
ID
ColumnHeader
OtherColumns
1
[Table]
OtherData
After expansion
ID
ColumnHeader
OtherColumns
1
FakeEmail#email.com
OtherData
1
FakeEmail2#email.com
OtherData
Target output
ID
ColumnHeader
OtherColumns
1
FakeEmail#email.com# FakeEmail2#email.com
OtherData
*The delimiter can be anything (not neccesarily a #)
Assume you have a table like this.
Table (in green) contains data structured like this.
To achieve the concatenation you're after as follows:
Add a custom column with the following code.
Text.Combine([ColumnHeader][Column Header A],"# ")

Can I create a link based on multiple columns in Siebel?

Our Siebel application has 2 tables, both of them sharing 4 text fields. I want to create a link, to show as a child BC all the records from the second table, having the same 4 values as the current record from the first table.
In SQL this could be easily done with something like this:
select *
from table1 t1
left join table2 t2 on (t1.a = t2.a and t1.b = t2.b and t1.c = t2.c and t1.d = t2.d)
where t1.row_id = '1-23456';
Can I build something similar in Siebel 7.8?
I thought creating a link based on any of the text fields (the one with the least repeating values), and then filter the 3 remaining fields in the child BC search spec, but... how do I reference the parent BC values in a search spec? (Without using profile attributes or calculated fields, which would impact too much on performance).
Note: I can't change the tables for this task, however the child BC will be created for this task and won't be used elsewhere.
You will have to use a link search spec. Links can have searchspec, for exactly this reason. Go to links and search for NOT NULL on the searshspec column to see vanilla examples. The link searschspec is always applied on the child bc, so to accesss fields from parent bc, use the ParentFieldValue function
example:
[Account Id] = ParentFieldValue ("Account Id")
on link "Account Product - CPG/CG SVP Product Baseline - for Adding Data"

Formatting a portal in FileMaker 13 to show related text only and not keys

I am using FileMaker Pro 13. I need to add Portal to show data from related table.
Some fields which I wanna add to Portal are "Foreign keys" from that related table that are linked-related to third table.
Results I am getting in Portal from those fields are numbers, but I need data (text) from that third table that is related to that "Foreign key".
Is it possible to create portal that shows text related to that foreign key, and if it is, how to achieve that?
Thanks a lot!
Example schema is on link https://www.lucidchart.com/invitations/accept/e45dfdfd-185d-46c8-ad9e-e8e8dc270ee7
In general words, I want to add Portal on layout based on Table3, so I can view related data from Table2, and it would have fields tbl2item, TBL1_foreign key (from where I pull data from Table 1 when I enter data in Table 2, using pop up menu). And in Portal data I need TBL1_foreign key to be represented as text from related table instead of auto-numbers.
Assuming the relationship:
Table 1 --> Table 2 --> Table 3
You are in the layout based on Table 1. Make sure there is relationship to Table 3 and it is in the same group (TOG) in Manage Databases. Just place the field with text from the Table 3 on your portal row and it should work.
Make sure you select the correct relationship for Table 3. In drop-down list it should be in "Related" group. Should look like "Table 3::myFiled" on the layout, with the name the same as the name of your table instance (TO) from "Manage database" which could be different from your base table name
The other option would be to use value list.
I do not see your file, so if it does not work for you, post more details about your setup.

I need serious help in changing the vaue of a column within the same column by going 2 rows up and changing the value

I am a DBA of 7 months so please bear with me. I am needing to write a code that will find a particular ProductIdentifier. When this particular ProductIdentifier is found, 1. I need to grab this ProductIdentifier. 2. I need to go 2 rows up and place that ProductIdentifier in the field that is 2 rows above it.
Here is my code(everything is sorted properly already in this table)
SELECT
SipID,
SaleInvoiceID,
AssociationNumber,
Priority,
TotalPrice,
TotalCost,
SerialNumber,
ContractNumber,
ActivatedThroughPAW,
DateCreatedatMidnight,
ReceivedDate,
InvoiceIDByStore,
Location,
ProductIdentifier,
Description,
ShortDescription,
CategoryName,
RevenueStreamID,
RevenueType
FROM REVISEDTABLE.
I will better show you what needs to be done ![enter image description here][1]
ProductIdentifier
AWUPG2001RGP -- replace this product identifier with the 'AWRPNS000%'
POSC0021PRW
AWRPNS000343 --take this product identifier
What I need for this code to do is this: whenever I find any ProductIdentifier like 'AWRPNS000%', I need for the query to take this and go 2 rows up and replace whatever ProductIdentifier is in this with 'AWRPNS000%'. I then need to insert the results into a table. I believe the best thing to do is to select the ProductIdentifier row again and give it an alias. This will be the row that I need to transform. I can then do a comparison to see if things worked out. I do not know how to write the code to do the actual grabbing of the ProductIdentifier and going up 2 rows and replacing it, so any help or input would be greatly appreciated.
So what does two rows up mean. Why is it two rows up.
e.g.
ID Class Type Date
1 1 2 20/12/2012
2 1 2 21/12/2012
3 1 2 22/12/2012 *
ie yes ID is two rows up but that's because The records are in ID and date order and there are at least three of them.
If you can come up with that rule e.g.
Select * From SomeTable Where Class = 1 and Type = 2 And Date = 20/12/2012
Then all your problems go away...