I have the following sentences in the first table:
key desc
single The single standard deduction for {2018} is {12000}.
MFJ The MFJ standard deduction for {2018} is {24000}.
I want to merge {info} from the second table:
key value
single*2018 12000
mfj*2018 24000
I want to be able to have a place holder {2018} so a select join can show the description in the first table to change when tax years are changed ie from 2018 to 2019.
Related
I am trying to achieve the following challenge but I am not sure how to tackle it.
I have a table called "salesman_data" with 2 columns. Each columns represents a salesman (e.g. salesman_id_1 and salesman_id_2). Each column contains data about products which have been sold by the corresponding salesman. The data stored is the product ID. For instance, the salesman salesman_id_1 sold products whose ID are 123, 456, 789, etc. The same applies for salesman_id_2. The table is the following:
Table salesman_data
salesman_id_1
salesman_id_2
123
321
456
654
789
987
...
...
I have to calculate the sales ratio. The ratio is defined as (nb of product sold by the salesman) / (total nb product sold by everyone). The required output for the answer is each salesman with their sales ratio. Then ordering data by salesman id. In my understanding, the output should look like this:
salesman_id
ratio
1
30.1
2
69.9
Since the original table does not allow me to sort data by salesman id, I would need to create an entire new table beforehand. I was thinking about doing this:
Create a new table
Calculate the ratio
Insert the ratio into the newly created table
Query the data from the new table
I do not know if my process is the most efficient. What do you guys think ?
I am currently using Access 2016 and am trying to create a query that is pulling in a different query and a table as its 2 source elements. Below is an example of the structure
table:
entity code
legal AP01
admin AP02
acct AP03
query1:
date total billing
1/1/2019 $10 000000-AP01-abcxyz
1/5/2019 $12 000000-AP01-abcxyz
1/12/2019 $15 000000-AP02-abcxyz
I've tried thinking about how to do a join, but since the billing field is a long text due to the fact that some strings are much larger than 255 characters, that is out of the question. So maybe using IN somehow, and the query would look for the code field value in table within the billing field value in query1, and display the following output
query2:
date total billing entity
1/1/2019 $10 000000-AP01-abcxyz legal
1/5/2019 $12 000000-AP01-abcxyz legal
1/12/2019 $15 000000-AP02-abcxyz admin
Using that output I could group by entity and sum total to show total spend within a department. I dont want to have to extract down to excel, run vlookup and find, then re-import it back in to access. There would be no point if I wanted to just do it all in excel. Can this be done within an access query?
You can use instr():
select q1.*, t1.entity
from q1 join
t1
on instr(q1.billing, t1.code) > 0
You can use like:
select
q.*, t.entity
from query1 as q inner join tablename as t
on q.billing like '*-' & t.code & '-*'
From your expected results I assume that code will always be inside billing in the form: ...-AAAA-....
If this is not the case, remove the dashes and use it like this:
on q.billing like '*' & t.code & '*'
I have a set of related rows which I need to display in a single line. For example, the data I have is in different rows.
"ID" RecordDate "ExpType" "OrigBudget" "ActualCost"
1001 1-5-2017 Hardware $ 5000
1001 2-6-2017 Hardware $ 5200
The Original budget is approved at an earlier time for the same record but the Actual cost often differs and is recorded at a later date. I want the output as
ProjectID YearofEntry ExpenseType OrgBudget ActualCost <BR>
1001 2017 Hardware $ 5000 $ 5200 <BR>
I have tried group query to aggregate it based on ExpenseType and ProjectId but not successful in getting it into a single row so far.
if you always just have two rows for each ExpType - one with the original budget and one with the actual costs - you could simply use a GROUP BY:
SELECT ID AS ProjectID
,YEAR(RecordDate) AS YearofEntry
,ExpType AS ExpenseType
,MAX(OrigBudget) AS OrgBudget
,MAX(ActualCost) AS ActualCost
FROM yourtable
GROUP BY ID
,YEAR(RecordDate)
,ExpType
Try This:
SELECT ID,
Year([RecordDate]) AS YEARofEntry,
ExpType,
Sum(OrigBudget) AS SumOfOrigBudget,
Sum(ActualCost) AS SumOfActualCost
FROM youtable
GROUP BY ID,
Year([RecordDate]),
ExpType;
I have a table that provides a point-in-time snapshot with the following headings:
| Cust# | Last Trans. | Charge | Quantity |
Every month, I will receive a file from a third party with transactions that will add new cust# or change existing customer information. I am having problems when there are multiple updates to the same Cust# in one month.
For example:
processing the following transaction file:
should yield the following snapshot table:
It may not be the best method, but now I have 3 separate queries to handle NEW, CHANGE and CANCEL. There are no problems with NEW and CANCEL.
Here's how my CHANGE query is set up:
UPDATE snp
INNER JOIN tr
ON snp.[Cust#] = tr.[Cust#]
SET
snp.[Last Trans] = tr.Transaction,
snp.Charge = snp.Charge + tr.Charge,
snp.Quantity = tr.Quantity
WHERE tr.Trans='CHANGE'
Note that Charge is incremental and Quantity is not. Updating Charge is working as expected, but Quantity is not. I do not necessarily get the latest quantity.
How do I ensure that if there are any changes to one customer, that the last Quantity field taken is from the latest CHANGE row (ie. max ID of that cust#)?
SELECT * FROM snp
WHERE ID IN (SELECT MAX(ID)
FROM tr
GROUP BY CUST#)
The inner query would give you all customers' max ID. You can filter the cust# based on your change criteria. The outer query would give you all the details of that row. You can then use those values in your queries.
All,
I have three total tables. The first table 'rollup1' contains the number of views and number of clicks for a campaign, as well as a one-up number for the day field (largest number in column represents the current date) A second table 'rollup2' contains the earnings for the campaign. It also contains the same one-up number for the dayfield. The third table 'campaigns' contains the ID/names for the campaigns. campaigns.id = rollup1.id = rollup2.id and rollup1.day=rollup2.day
I want to generate an SQL query that lists the campaign id, name, specific calculated value from yesterday, and specific calculated value from today. The specific calculated value I'm looking for is (earnings/clicks)*1000.
The results will look like:
id | name | yesterday | today
a | Campaign1 | $0.05 | $0.010
I think I can use case statements, but I can't seem to get it correct. Here's what I have so far. It calculates the formula for yesterday, but not the one for today. I need these to be side by side.
select campaigns.id, campaigns.name, rollup1.views,rollup1.clicks,rollup2.costs,round((rollup2.costs/rollup1.views)*1000,2) as yesterday
from campaigns,rollup1,rollup2
where campaigns.id = rollup1.campaign_id and campaigns.id = rollup2.campaign_id
and rollup1.dayperiod = rollup2.dayperiod
and rollup1.dayperiod = (SELECT (max(rollup1.dayperiod) -1) FROM rollup1)
Thanks for any help you can provide.