How to evaluate multiple rows based on a column - hive

Table ActualTO(60000+ records daily increment) have columns rid, caid & consent .rid is primary key.there will be multiple unique caid's corresponding to each rid.consent Column contains either consented or not-consented. How to add a new column which contains list caid's which are not-consented corresponding to each rid.
Rid caid consent new_col.
1001 qc101 consented qc102;qc111
1001 qc102 notconsented qc102;qc111
1001 qc111 notconsented qc102;qc111
1221 qc244 notconsented qc244;qc201
1221 qc202 consented qc244;qc201
1221 qc201 notconsented qc244;qc201

Related

Custom validation rule based on query results

I have a table that stores personnel assigned to a project and if they are removed from the project.
Each project has several people filling roles.
Several of the roles can be filled by multiple simultaneously but a few can only be filled by one person at a time.
If a person gets removed from the project, their record gets tagged with a date of removal in a specified date field.
[projectNumber][employee][role][removedDate]
[employee] and [roles] are lookup fields
I have a query that identifies the roles that should have one individual filling that role at a time.
SELECT first(projectNumber) AS pn, employee, role
FROM [Table]
WHERE projectNumber = "NUMBER" and removeddate is null and (role = 9 or role = 10 or role =2 or role =3 or role =1)
GROUP BY pn, role;
This returns the roles that can only have one person in that role, for a specific project number. If that role is not filled then nothing is returned for that record in this query.
I am trying to get the form to reference the query with a dlookup but I am not sure what I am doing.
How can I create a validation rule that checks to see if the roles are filled, per project, and returns an error if yes?
Example Table:
[projectNumber][employee][role][removedDate]
1111111 A 1
1111111 B 2
1111111 C 3
1111111 D 4
1111111 E 5
1111111 F 9 2/20/19
1111111 G 4
1111111 H 5
1111111 I 9
1111111 J 10
Here would the result of the query identifying all the roles that can only have one individual assigned to that role that have not been removed.
[projectNumber][employee][role][removedDate]
1111111 A 1
1111111 B 2
1111111 C 3
1111111 I 9
From these results I want the validation checker to reference these results if someone were to add: Employee M to project 1111111 to role 1, 2, 3, 9. It should return an error since those roles are assigned.
The validation checker would NOT return an error if someone tried to add: Employee N to project 1111111 for role 10.

Select items where count in another field matches (not updatable)

Here I am trying to get the record for my products where the # swab location in Main table matches the count of swab locations in swab Table and Users can checked off the Y/N to verify that the description of the locations are correct.
Here is the example of my 2 tables.
tblMainEquipment
Asset_ID EquipmentName Num_SwapLocations Verified
234 Saijimon 2 N
235 Pasquale 3 N
tblMainSwapLocations
Asset_ID Swap_location
234 Particle Cannon
234 RailGun
235 Particle Cannon
I use the following query to count the number of records, i avoided using a having query to combine both tables since it is not updatable.
qryMainSwapLocationCount
SELECT MSL.Asset_ID, Count(Asset_ID) AS [Count]
FROM tblMainSwapLocation AS MSL
GROUP BY MSL.Asset_ID;
This will give me the result of
qryMainSwapLocationCount
Asset_ID count
234 2
234 1
I used the following as a record source for my form to allow users to verify the inputs.
SELECT MEQ.Asset_ID, MEQ.Equipment_Name,MEQ.Num_swapLocations MEQ.Verified
FROM tblMainEquipment AS MEQ, qryMainSwapLocationCount AS MSLC
WHERE (((MEQ.Asset_ID)=[MSLC].[Asset_ID]) AND ((MEQ.Num_SwapLocations)=[MSLC].[Count]);
This result would be
tblMainEquipment
Asset_ID EquipmentName Num_SwapLocations Verified
234 Saijimon 2 N
However this record set is not editable. Is there any reasons for this?
I think you should put your table tblMainEquipment as your recordsource and bring all the fields from that on to your form:
Then insert an unbound textbox (perhaps close to your Num_SwapLocations field for easy comparison):
Then in this new textbox, put the following in the ControlSource:
=DCount("ASSET_ID","tblMainSwapLocations","ASSET_ID=" & [Asset_ID])
Then open your form and it should count the number of records in table tblMainSwapLocations that have the same Asset_ID as the record currently showing:
You'll then be able to update the Verified field in your tblMainEquipment table.

Is it possible to match the "next" unmatched record in a SQL query where there is no strictly unique common field between tables?

Using Access 2010 and its version of SQL, I am trying to find a way to relate two tables in a query where I do not have strict, unique values in each table, using concatenated fields that are mostly unique, then matching each unmatched next record (measured by a date field or the record id) in each table.
My business receives checks that we do not cash ourselves, but rather forward to a client for processing. I am trying to build a query that will match the checks that we forward to the client with a static report that we receive from the client indicating when checks were cashed. I have no control over what the client reports back to us.
When we receive a check, we record the name of the payor, the date that we received the check, the client's account number, the amount of the check, and some other details in a table called "Checks". We add a matching field which comes as close as we can get to a unique identifier to match against the client reports (more on that in a minute).
Checks:
ID Name Acct Amt Our_Date Match
__ ____ ____ ____ _____ ______
1 Dave 1001 10.51 2/14/14 1001*10.51
2 Joe 1002 12.14 2/28/14 1002*12.14
3 Sam 1003 50.00 3/01/14 1003*50.00
4 Sam 1003 50.00 4/01/14 1003*50.00
5 Sam 1003 50.00 5/01/14 1003*50.00
The client does not report back to us the date that WE received the check, the check number, or anything else useful for making unique matches. They report the name, account number, amount, and the date of deposit. The client's report comes weekly. We take that weekly report and append the records to make a second table out of it.
Return:
ID Name Acct Amt Their_Date Unique1
__ ____ ____ ____ _____ ______
355 Dave 1001 10.51 3/25/14 1001*10.51
378 Joe 1002 12.14 4/04/14 1002*12.14
433 Sam 1003 50.00 3/08/14 1003*50.00
599 Sam 1003 50.00 5/11/14 1003*50.00
Instead of giving us back the date we received the check, we get back the date that they processed it. There is no way to make a rule to compare the two dates, because the deposit dates vary wildly. So the closest thing I can get for a unique identifier is a concatenated field of the account number and the amount.
I am trying to match the records on these two tables so that I know when the checks we forward get deposited. If I do a simple join using the two concatenated fields, it works most of the time, but we run into a problem with payors like Sam, above, who is making regular monthly payments of the same amount. In a simple join, if one of Sam's payments appears in the Return table, it matches to all of the records in the Checks table.
To limit that behavior and match the first Sam entry on the Return table to the first Sam entry on the Checks table, I wrote the following query:
SELECT return.*, checks.*
FROM return, checks
WHERE (( ( checks.id ) = (SELECT TOP 1 id
FROM checks
WHERE match = return.unique1
ORDER BY [our_date]) ));
This works when there is only one of Sam's records in the Return table. The problem comes when the second entry for Sam hits the Return table (Return.ID 599) as the client's weekly reports are added to the table. When that happens, the query appropriately (for my purposes) only lists that two of Sam's checks have been processed, but uses the "Top 1 ID" record to supply the row's details from the Return table:
Checks_Return_query:
Checks.ID Name Acct Amt Our_Date Their_Date Return.ID
__ ____ ____ ____ _____ ______ ________
1 Dave 1001 10.51 2/14/14 3/25/14 355
2 Joe 1002 12.14 2/28/14 4/04/14 378
3 Sam 1003 50.00 3/01/14 3/08/14 433
4 Sam 1003 50.00 4/01/14 3/08/14 433
In other words, the query repeats the Return table info for record Return.ID 433 instead of matching Return.ID 599, which is I guess what I should expect from the TOP 1 operator.
So I am trying to figure out how I can get the query to take the two concatenated fields in Checks and Return, compare them to find matching sets, then select the next unmatched record in Checks (with "next" being measured either by the ID or Our_Date) with the next unmatched record in Return (again, with "next" being measured either by the ID or Their_Date).
I spent many hours in a dark room turning the query into various joins, and back again, looking at functions like WHERE NOT IN, WHERE NOT EXISTS, FIRST() NEXT() MIN() MAX(). I am afraid I am way over my head.
I am beginning to think that I may have a structural problem, and may need to write the "matched" records in this query to another table of completed transactions, so that I can differentiate between "matched" and "unmatched" records better. But that still wouldn't help me if two of Sam's transactions are on the same weekly report I get from my client.
Are there any suggestions as to query functions I should look into for further research, or confirmation that I am barking up the wrong tree?
Thanks in advance.
I'd say that you really need another table of completed transactions, it could be temporary table.
Regarding your fears "... if two of Sam's transactions are on the same weekly report ", you can use cursor in order to write records "one-by-one" instead of set based transaction.

Join two tables and return data from either one or the other based on data

SQL 2012
Cannot change tables
Have two tables in question, both tables are identical
(I didn't design this)
Table A has application data. We accept applications and at the time of application we require a minimum of information - many values here can be null (or some placeholder like NA etc). It is assigned an application number (application id). If the application is accepted, we require more information - and we verify it.
Leading us to Table B - a copy of A except it is only populated with accepted applications - and verified data. So an application id will only exist in Table B if the manager accepts it. Sometimes, at the application process, the data is correct and no changes were made - leading to an application id having the exact values in both tables. Sometimes, the data changes or is added (we require all fields upon acceptance).
I would like to an easy way to capture all applications and the most current/verified data.
For instance:
Table A (Active Applications)
ApplicationID Phone State
1234 123-456-7890 AK
5678 246-802-4680 NULL
Table B (Approved/Accepted Applications)
ApplicationID Phone State
5678 246-802-4680 NY
Application 5678 was approved and, for demonstration only, the state was verified to be NY.
Application 1234 was not approved to date (but maybe in the future).
I would like to write a query which gives the following result:
ApplicationID Phone State
1234 123-456-7890 AK
5678 246-802-4680 NY
Desired behavior is essentially...return Table A unless the ApplicationID exists in Table then give me Table B instead.
Table A does contain every application expired or not, but there is an expiry date (applications good for 10 days) and it will be easy to cull those out based on that date.
Just flummoxed by needing approved and active applications.
Any help greatly appreciated.
--EDIT--
Thank you...but how do I handle the placeholders (like NA or XX) or when the verified data is deifferent from the application data? Say there is a third active application as so:
Table A (Active Applications)
ApplicationID Phone State
9876 234-432-1234 NY
Table B (Approved Applications)
ApplicationID Phone State
9876 234-432-1234 TX
The application was accepted by virtue of its existance in Table B but the state was verified to be TX and not NY.
I would like to see an output as such...Table A data if not in Table B. IF In Table B then Table B data.
ApplicationID Phone State
1234 123-456-7890 AK
5678 246-802-4680 NY
9876 234-432-1234 TX
Select a.applicationid, case when b.phone is null then a.phone else b.phone end as phone, case when b.state is null then a.state else b.state end as state
From a
Left outer join b on a.applicationid = b.applicationid
select
a.applicationid as a1, a.phone as a2, a.state as a3,
b.applicationid as b1, b.phone as b2, b.state as b3,
isnull(b.applicationid, a.applicationid) as applicationid,
isnull(b.phone, a.phone) as phone,
isnull(b.state, a.state) as state
from a
left outer join b on a.applicationid=b.applicationid
(omit line 2 and 3, these are just to show what the column entries are before isnull())

Grouping attributes in SSAS

I have an account dimension where the same account can have multiple account numbers. So I setup a durable key to group these accounts. So for example
Durablekey AccountNum
1 1
1 2
1 3
2 4
3 5
The durablekey has no business meaning. I would like to have an attribute in cube that displays the accountnum but would essentially have the durablekey as the key. So if I selected accountnum 2 it would pull all the information for everything with a durablekey of 1. If I simply set the accountnum as the name and durablekey as the key I get a duplicate error during processing as expected.
Is this possible to do?
Hi there is sample data http://msftdbprodsamples.codeplex.com/releases/view/55330
You need to make Parent->Child Hierarchie, that Account key was normal integer key and other Accounts will have Parent Account key, which show to Parent Account. Parrent Account can have multiple other Accounts:
AccountKey | ParentAccount | Code
1 - 102
2 1 10255
3 1 10266
4 3 13444
5 3 13555
There is a lot of examples in internet just type - SSAS Parent - Child :
http://my.safaribooksonline.com/book/databases/microsoft-sql-server/9780735626201/creating-dimensions/creating_a_parent-child_dimension
Also you can use sample database and SSAS projects, there is everything done on working Cube...