Using lookup transformation for 2 columns at the same time - ssis

I want to use lookup transformation for 2 columns at the same time in SSIS. For example, if there are 3 columns ProductID,CreatedDate,Pname I need to compare 2 columns say ProductID and CreatedDate at the same time so that only if a row has same ProductID but different Created Date it should go in no match output. Currently my transformation is just using productid and if its already exists, it is putting in matched rows even after having a different CreatedDate.
As per above example, both ProductID with 1 should be there in no match output.
How can we implement this in SSIS?

It's very simple. Currently I believe you have only source.ProducID mapped to destination.ProductID in lookup.
All you need to do is map source.CreatedDate to destination.CreatedDate.
You need to do something like this :

Related

Create a column with daily number of orders in SSIS?

I'm trying to create a new column with the daily orders (the count of OrderNumber for each day). Since I have data coming from multiple sources, I'm using SSIS. My final table should look like this:
Date | Product Number | Quantity Sold | Number of Orders (for that date)
I've tried using Aggregate, but it's not working because of the other columns. I was thinking about creating a parallel source (the same staging table), on which I would use Aggregate to find the number of daily orders, and then find a way to bring it back to the final table, but there must be an easier way?
Aggregate transform takes and outputs only columns you select. So, for your case, select Date, Product, Quantity and some column for Order Count - we will return to this later. Specify Group by for the first two columns, Sum for the third, and Count for the forth. At output you will receive four columns with desired result.
Source column for Count should represent orders and does not include columns used in the first three functions. If you need to use one of these three columns, create a copy of it with Derived Column transfer. I would not recommend using (*) (all columns) for Count, since it will count rows with Null values as well.

Generate a query that show the times that questions get wrong

I have a table named countwronganswer with columns cwa_id, question_num. How can I generate a table with query that shows two columns, one column lists all the question_num and second column lists the number of times that cwa_id that related to the question_num.
Question Number |Total # of Mistake |
1 12
2 22
..etc
ATTENTION: This question was asked without the awareness of the existence of count or Groupby method because of the knowledge level at that state. Count() or Groupby() were the key to generate the 2nd column of total # values which I did not aware of completely, therefore, any attempt, at that point of time, to write the code for the data will be close to meaningless. Vote up if possible if you think its useful or resolved your issue.
Probably something like this
SELECT question_num, COUNT(cwa_id) total_mistakes
FROM countwronganswer
GROUP BY question_num
select question_num , count(cwa_id)
from tableName group by question_num

How to collapse MS Access Table rows by matching IDs

I have a table similar to the Example Source Table shown below that I would like to collapse based on the ID field (see Example Collapsed Table). I can do this with code but it inflates my Access database beyound the 2 GB maximum size so I'm hoping there is a way to do it with a query. I should probably note that for any given ID value I don't need to worry about more than one record having a value in field One, Two, Three, or Four.
Example Source Table:
ID One Two Three Four
1 My Is
1 Matt
1 Name
2 My Is Matt
2 Name
3 My Name Is Matt
Example Collapsed Table:
ID One Two Three Four
1 My Name Is Matt
2 My Name Is Matt
3 My Name Is Matt
You can use an aggregate query which groups by ID and returns the Max() for each of those other 4 columns within each ID grouping.
SELECT
ID,
Max(One),
Max(Two),
Max(Three),
Max(Four)
FROM tblSource
GROUP BY ID;
If you want to store the results in a new table, convert the query to a "make table query". If you already have your destination table created and want to add those results to it, convert the query to an "append query".
If you're approaching the 2 GB db file size limit, first use Compact & Repair to discard unused space. If compact doesn't give you enough working room, create another db file and store the new (collapsed) table there. You can link to it from your original database.

Difficult MS Access Query - how to combine them?

I am trying to build an access report based on data from multiple different tables within the database.
I have 3 columns which perform calculations, and I am wondering how to put this query together. All 3 columns deal with dates, but calculate them differently.
The first column retrieves the most recent date of action for a userid if the type of action is "B":
select pid, Max(date) as most_recent
from actions
where ref = 'B'
group by pid;
The second column performs a calculation based on 2 fields, one is a date and one is a number in months. I am unsure how to add these two fields so that the number is added to the date as a number of months.
what i have so far is:
select nummonths,Max(lastvisit) from users
the third column I need to select the first date thats in the future for each user (next appointment date), there will be dates before and after this date so its a little difficult:
select uid,date from visits
The code for the last 2 queries needs to be slightly modified, and I was wondering what the best approach would be to join these all together? A type of join?
If you need to build a report with data from the 3 queries, you will need related data to join them. In that case, please send the structure of the tables.
If you need to show 3 lists in one report, you can use subreports: create a new empty report. In design mode, you can add 3 subreports from the toolbox bar. To each of the subreport assign the record source property to the corresponding sql.
regards
I am unsure how to add these two fields so that the number is added to the date as a number of months.
Use the DateAdd() function:
SELECT DateAdd("m", 2, LastVisit) FROM ...
Results in a date two months from the LastVisit date.

Merge columns in MySQL SELECT

I have a table that stores a default configuration and a table that stores a user configuration. I can join the two tables and get all the info I need however I was hoping there might be a cleaner way to overwrite one column with the other when a value exists in the second column.
Example:
Current query result:
id defaultValue userValue
1 one ONE
2 two
3 three THREE
4 four
Desire query result:
id value
1 ONE
2 two
3 THREE
4 four
Maybe there isn't a good way to do this... Thought I'd ask though as it's probably faster to do it in MySQL if a method exists than to do it in PHP.
You can use COALESCE() for this:
SELECT id, COALESCE(uservalue,defaultvalue) AS value
FROM table