I have a Form which splits into 3 sections
As a result of this. I have some fields which are duplicated.
I am trying to pull rows from the 'FormData' spreadsheet page. Then display them in the 'Report' spreadsheet page. Easy enough.
I then want to merge the duplicated fields together in the report. Fields will only be merged where all but one field is empty.
i.e "Select Col2 where Col1 =''"
FormData
A = Timestamp
B = Name
C = Account Name
D = Contact
E = Notes
F = Task
G = Location
H = Freight to Store
I = When Goods Arrive
J = Freight to Customer
K = Priority
L = Assign To
M = Status
N = Supplier
O = Freight to Store
P = When Goods Arrive
Q = Freight to Customer
R = Priority
S = Assign To
T = Status
U = Priority
V = Assign To
W = Status
Report
FormData column to merge
B & C (Name:),(Account Name: Optional)
K, R, U (Priority:)
L, S, V (Assign To:)
G & N: (Supplier:),(Location:)
H, O (Freight to Store:)
I, P (When Goods Arrive:)
J, Q (Freight to Customer: Optional)
M, T, W (Status:)
I have worked out how to merge cells. Using the below formula.
Example for Merging Column B (Name) and Column C (Account Name)
=iferror({query({IMPORTRANGE("URL","FormData!B2:B20000")},"Select Col1 where Col1 <>''");query({IMPORTRANGE("URL","FormData!B2:B20000"),IMPORTRANGE("URL","FormData!C2:C20000")},"Select Col2 where Col1 =''")})
I am not sure if this goes beyond using a formula or if a script will need to be created.
Either way I will require assistance.
I greatly appreciate any help offered. Am working on this until I have figured it out.
Many Thanks.
Related
Actually i want to copy one tables data to another table. it has no unique id , the only relation between two are a "fra" number and a 'pra' number but both are not unique . but fra and pra (r concatenate ) is unique for each. and one table data is sex (customer table) and another is gender(new_customer table) the gender is Boolean, sex is string of m and f . how can i copy from customer table to new_customer table
I tried these way
UPDATE new_customer JOIN customer
SET registrations.name = customer.nam,
registrations.surname = customer.vornam,
registrations.ort = .ort,
registrations.phone = customer.telmbl,
registrations.surname = customer.vornam
WHERE registrations.fra = customer.fra
and registrations.pra = customer.pra;
Any body to help me?
something like following, you can try.
UPDATE new_customer AS new_c, customer AS old_c
SET
new_c.name = old_c.nam,
new_c.surname = old_c.vornam,
new_c.ort = old_c.ort,
new_c.phone = old_c.telmbl
WHERE
new_c.fra = old_c.fra
AND new_c.pra = old_c.pra;
So let's say you have column A,B,C. On duplicate key, let's say you do A = {some statement here}, B = {some statement here}, and C= New_A + New_B. Can I use what would be the new values of A and B in order to determine the new value of C, or do I have to retype the expressions for the new A and B? Thanks!
I think you can do it. If you do:
ON DUPLICATE KEY UPDATE
A = A + 1, B = B * 2,
C = A + B
I believe the updates are executed left to right. So when it gets to C = A + B, A and B contain the new values.
I have built an interface, where the user fetches records from the database. User has the option of specifying 0 or more of the filters. There are four filters A, B, C, D (let's say these are the fields in a certain table)
Here's what my query should look like:
select * from table
where (A = v1 or B = v2 or C = v3) and D = v4
I am trying to come with a way to formulate the query, whereas when a specific filter is specified, it is applied, if it isn't, it is ignored. But this should hold for all the sixteen cases.
What I have been able to come up with so far are these methods:
select * from table
where (
(A = v1 and 1)
or (B = v2 and 1)
or (C = v3 and 1)
)
and D = v4
v1 or other values are set to -1 when they are not specified. So in case they are not specified, they're simply ignored, because then the other filter (from among A, B, C) is used. But this fails in the case when none of A, B, and C are specified. In that case, false is Anded with D, and D is not applied.
Is there a way to come with a where clause for this case? I am open to programmatic solutions to this one as well, where I add or not add clauses through code, but I would prefer it this way. And I would really not want to have a lot of if-else statements.
Thank you!
What about using case construct
select *
from table
where (A = CASE WHEN v1 IS NOT NULL THEN v1 else '' END)
OR (B = CASE WHEN v2 IS NOT NULL THEN v2 else '' END)
OR (C = CASE WHEN v3 IS NOT NULL THEN v3 else '' END)
OR (CASE WHEN v1 is null and v2 is null and v3 is null then 1 else 0 end)
and D = v4
if v1-v4 are the values you're searching for and all of them are -1 if not specified, you can do this:
SELECT
*
FROM
table
WHERE
(
(A = v1 OR -1 = v1)
or
(B = v2 OR -1 = v2)
or
(C = v3 OR -1 = v3)
)
AND
(D = v4 OR -1 = v4)
Databases have a hard time optimizing dynamic where clauses. Typically, they'll produce a plan that's optimal for the first invocation. So if your first search is for filter A and B, the query plan will be optimized for that. The next query will also use that plan, even if it's using filters C and D. Adding where clauses in code tends to perform much better.
But it is possible, for example:
where (
A = #FilterAValue
or B = #FilterBValue
or C = #FilterCValue
)
and D = coalesce(#FilterDValue, D)
And then you can toggle the filters with the FilterXValue parameters. If the filter for A, B or C is null, the other parts of the or will still be evaluated. A = null or B = 1 is the same as unknown or B = 1 which is only true when B = 1.
I've written a simple linq query as follows:
var query = from c in context.ViewDeliveryClientActualStatus
join b in context.Booking on c.Booking equals b.Id
join bg in context.BookingGoods on c.Booking equals bg.BookingId
select new { c, b, bg };
I have filtered the previous query with a number of premises and then needed to group by a set of fields and get the sum of some of them, as so:
var rows = from a in query
group a by new {h = a.c.BookingRefex, b = a.c.ClientRefex, c = a.b.PickupCity, d = a.b.PickupPostalCode} into g
select new
{
Booking_refex = g.Key.h,
Client_refex = g.Key.b,
//Local = g.
Sum_Quan = g.Sum(p => p.bg.Quantity),
};
I'd like to get a few values from a which I haven't included in the group by clause. How can I get those values? They're not accessible through g.
The g in your LINQ expression is an IEnumerable containing a's with an extra property Key. If you want to access fields of a that are not part of Key you will have to perform some sort of aggregation or selection. If you know that a particular field is the same for all elements in the group you can pick the value of the field from the first element in the group. In this example I assume that c has a field named Value:
var rows = from a in query
group a by new {
h = a.c.BookingRefex,
b = a.c.ClientRefex,
c = a.b.PickupCity,
d = a.b.PickupPostalCode
} into g
select new {
BookingRefex = g.Key.h,
ClientRefex = g.Key.b,
SumQuantity = g.Sum(p => p.bg.Quantity),
Value = g.First().c.Value
};
However, if c.Value is the same within a group you might as well include it in the grouping and access it using g.Key.cValue.
Just add those field in the
new {h = a.c.BookingRefex, b = a.c.ClientRefex, c = a.b.PickupCity, d = a.b.PickupPostalCode}
they will be accessible in g then.
So similar questions have been asked with not much of an answer....
I have a Stats Table related to a Branch table. The Stats records contain pc stats of a particular bank branch.
Branch
+Code
+Name
+Area
...
Stats
+BranchCode
+IP
+UpSpeed
+DownSpeed
...
Here is my linq query...
var stats = from st in store.Stats
join b in store.Branches on st.BranchCode equals b.Brcd
select new
{
st.ID,st.IP,st.Name,b.Brcd,b.Branch_Name..............
};
The issue is st and b have a LOT of fields, for now I guess I will type them all... but isn't there a solution to this? *Prevent the typing of all fields... something like a * wildcard?
Did try intersect however the types need to be the same!
Thanks
Gideon
1
var stats =
from st in store.Stats
join b in store.Branches on st.BranchCode equals b.Brcd
select new
{
Stats = st,
Branch = b
};
Creates anonymous instances with one Stats and one Branch.
2
var stats =
from b in store.Branches
join st in store.Stats
on b.Brcd equals st.BranchCode
into branchstats
select new
{
Branch = b
Stats = branchstats
};
Creates anonymous instances with one Branch and its Stats.
3
var stats =
from b in store.Branches
select new
{
Branch = b
Stats = b.Stats
};
Same as 2, If there's an association between the two types in the designer, then there's a relational property generated on each type.
4
DataLoadOptions dlo = new DataLoadOptions()
dlo.LoadWith<Branch>(b => b.Stats);
store.LoadOptions = dlo;
List<Branch> branches = store.Branches.ToList();
Here, DataLoadOptions are specified that automatically populate the Stats property when any Branch is loaded.