SSIS + split 1 row in multiple rows based on multiple columns
Hi all,
I have a flat file
Shop ID Check 1 Check 2 Check 3
500 OK
OK NOK
I want to transform this to staging as 3 rows
Shop ID Check number
Result
500 1
OK
500 2
OK
500 3
NOK
Anyone can tell me how to tackle this?
I basically have a table that has the columns I specified
Shop Check 1
Check 2 Check 3
500 OK
OK NOK
I now want to actually have them loaded in another table where I have multiple rows for each shop.
Shop Check
Result
500
1 ok
500 2
ok
500 3
nok
So basically I want to go from a column view to a row view. Is this possible?
In other words, I do see multiple rows for each shop ID which is awesome! But I would like to have instead of the result that number of the check. (1,2,3) with the result next to it :)
500 OK
500 OK
500 NOK
Similar Messages
-
Deleting duplicate rows based on three columns in Oracle 8i
Hi all,
The database we use is Oracle 8i.
The query below raises the too_many_rows exception when I launch an application. So I want to delete the duplicated rows :
select polarisation_1, polarisation_2
into v_pol1_tech, v_pol2_tech
from v_cfh_lien_element
where nom_lien = p_nom_lien
AND num_canal_1 = p_num_canal_1
AND freq_emise_1 = p_freq_emise_1;
Notice that with many possible values of the parameters p_nom_lien, p_num_canal_1 and p_freq_emise_1 then the exception is raised.
So how to delete generally the duplicated rows based on the three columns "nom_lien" , "num_canal_1" and "freq_emise_1" ?
Thank you very much indeed.Check the other thread with same question deleting duplicate rows based on three columns in Oracle 8i
-
Delete duplicate rows -- based on 4 columns -- how?
I asked this question on how to delete duplicates recently and received this suggestion which works well -- except --
With CTE AS
SELECT *, ROW_NUMBER() OVER (Partition by fld1 order by fld1) RowNum
FROM #tmpA
DELETE From CTE
WHERE RowNum > 1
-- the actual table I need to delete duplicate rows on is based on 4 columns. The following table contains 14,462 rows of which 14,348 are distinct -- based on the following 4 colums. Below is an image of a sample of the data contained in the
table for my question and to the right of that data is the column structures (data types). Is it possible to do something like the above example suggestion with the table in the image below? How to do that? I need to delete rows so that 14462
goes down to 14348. If I only reference one column for the delete -- this would delete like 7000+ rows. I only need to remove 114 rows.
Rich PAdd the other 3 columns to the partition.
Jason Long -
Need to color a Table row based on a Column value
Dear Alll
I have a requirement to color the rows of a table based on a column value in it. I have tried and surfed many useful materials over the net. but none of them solves my purpose. Please help me, I know that i can used OADataBoundValueViewObject and create a custom css file and apply color to a particular column of a table using a decode in the select statement of that VO.
But all i need is to color a particular row with a particular color. Need your help with this ........
Please do reply
Best Regards
Edited by: Antony Jayaraj on Mar 27, 2012 8:54 PMThese posts might help you.
How to change the row color based on Condition
Can we colour the rows in the column of a table
Regards,
Peddi. -
Unique row based on two columns and single column
Dear Members,
I have a table which contains duplicate rows, for which a query should be able to fetch the unique row from the table. Here the unique is not based on one column, but it should be on two columns and also check for uniqueness on one column.
create table addr ( firstname varchar2(10), lastname varchar2(10), area varchar2(3));
insert into addr values('bob', 'james', '1');
insert into addr values('bob', 'james', '1');
insert into addr values('harry', 'bert', '1');
insert into addr values('jimmy', 'bert', '1');
insert into addr values('sam', 'mac', '1');
insert into addr values('sam', 'knight', '1');
insert into addr values('tom', 'sand', '1');
insert into addr values('cat', 'mud', '1');
The output of query should contain 3 rows.
bob - james
harry - bert or jimmy - bert [ either one of them, but not both ]
sam - mac or sam - knight [ either one of them, but not both ]
tom - sand
cat - mud
SELECT firstname, lastname as total from addr WHERE area = '1' GROUP by firstname,lastname; This does not take of single column duplication..
Any suggestions..SQL> with t_data
as
select 'bob' as firstname, 'james' as lastname, '1' as area from dual union all
select 'bob', 'james', '1' from dual union all
select 'harry', 'bert', '1' from dual union all
select 'jimmy', 'bert', '1' from dual union all
select 'sam', 'mac', '1' from dual union all
select 'sam', 'knight', '1' from dual union all
select 'tom', 'sand', '1' from dual union all
select 'cat', 'mud', '1' from dual
SELECT
firstname,
lastname,
area
FROM
SELECT
t.*,
row_number() over(partition BY firstname order by 1) rn,
row_number() over(partition BY lastname order by 1) rn1
FROM
t_data t
WHERE
rn = 1
AND rn1 =1 ;
FIRSTNAME LASTNAME AREA
bob james 1
cat mud 1
jimmy bert 1
sam knight 1
tom sand 1
SQL> -
Formating the Row Based on one column value
Hi Friends
I am trying to format the Entire row based on the value of the first column in my Answers.
Example if first column value in 'F' now i want the Entire row to be colored
I can do conditional formating on one column but i want to do it on the entire row
F 8.1 % 12.0 %
E 5.2 % 3.5 %
M 2.3 % 3.3 %
If any one has done this or any suggestions please respond
Thanks
SangIts a Pivot View
F 8.1 % 12.0 %
E 5.2 % 3.5 %
M 2.3 % 3.3 %
the column 1 --> F,E,M are the Product
the column 2 --> 8.1% , 5.2% , 2.3% are the sales in year 2008
the column 3 --> 12.0 % , 3.5 %, 3.3 % are the sales in year 2009
So will i be able to apply the formating in pivot view based on one column to other column If yes please let me know how or
suggest if this can be done using the BI Office , or BI publisher
sing the BI Office i can do the formating in Excel but once i refresh the data all the formating is gone ... :(
I am donno BI Publisher if we have to use BIP please suggest any solution its very very very urgent and important report formating they need here ....
Thanks in advance David
sango -
Update multiple rows based on two columns in same row
I have a 1000 rows in a table I would like to update with a unique value. This unique value is a cocatenation of two columns in teh same row.
Each row has a (i) date and a (ii) time and a (iii) date_time column. I would like to update the date_time (iii) column with a cocatenation of the (i) date and (ii) time columns.
I know how I would update a single row but how can I update multiple rows with a cocatenation of each of the two columns - i.e put a different value into the date_time column for each row?this?
update table tab_name
set date_time =date||time
where your_condition -
How to split rows based on two columns..
Hi all...
I have a requirement.
I have product column, sell, purchace prices..(total of three columns) in a data set.
my data set is such a way that..if sale price exists...there is no purchase price and vice versa..
I need too present in a report ,two tables:
table 1 consists of only Sale price items
table 2 should contain only Pruchase Items.
Please see the below picture for clear understanding..
Is that doable? Where do we need to impose a condition?I tried to impose a condition but,it didnt seem to work
http://i51.tinypic.com/29xfdc6.jpg
Please help.Can you send me the template and xml file to [email protected]? I can try to help.
Did you try to filter out the records by the sale price or purchase price column not equal to null?
Thanks,
Bipuser -
How to retrieving latest row based on a column value
Hi,
Lets consider a scenario. I have a table which has a order number, count column which is our fact, a type column which contains types e.g. (A,B) with A has more priority then B. Now in our graph we are getting all rows i.e. if we have two rows in db for order #1 one for type A and one for type B, then it shows us data from both rows in graph.
But I need only to show one row of type A in this case as A has higher priority than B. The row with type B should not contribute in construction of my graph if type A for same row also exists.
I tried a solution, for which i created a new column at logical level which contain 1 for A and 0 for B. Now i put Max aggregation rule in it to get maximum value which will be row with Type A in our case. But it did not work.
How we will can achieve it in OBIEE?
Thanks.
Aasim Khan.Hi Steve,
I have a similar requirement... one of the columns in my table is a calculated value based on several xml fields,
<?xdofx:(MATH01+MATH02+MATH03+MATH04+MATH05+AA+AA1)+((FNDCD01+FNDCD02+FNDCD03+FNDCD04+FNDCD05+MCHCD01+MCHCD02) div '8')?>
if the resultant value above is less than 62, i do no want to display this entire row in the output. could you help me wout with this?
thanks
Domnic -
How to exclude entire row based on single column
Hello there,
I'm trying to hide an entire row if column does not equal 'E' and can't seem to get it to work. Here is code i am using inside the group:
<?for-each:current-group()?>
<?if@row:recordType != 'E'?><?end if?>
<?end for-each:current-group?>
What am i missing? Also note that the column i am trying to filter on is in the xml but not being displayed in the report.
Edited by: [email protected] on Mar 30, 2010 3:05 PMHi Steve,
I have a similar requirement... one of the columns in my table is a calculated value based on several xml fields,
<?xdofx:(MATH01+MATH02+MATH03+MATH04+MATH05+AA+AA1)+((FNDCD01+FNDCD02+FNDCD03+FNDCD04+FNDCD05+MCHCD01+MCHCD02) div '8')?>
if the resultant value above is less than 62, i do no want to display this entire row in the output. could you help me wout with this?
thanks
Domnic -
I'm dealing with an old database that's being phased out, and here's the version info (yes, it's really old):
Oracle8i Enterprise Edition Release 8.1.7.2.0 - Production
PL/SQL Release 8.1.7.2.0 - Production
CORE 8.1.7.0.0 Production
TNS for HPUX: Version 8.1.7.2.0 - Production
NLSRTL Version 3.4.1.0.0 - Production
I believe Frank Kulash gave me the solution to my original question, which was:
Sample data:
CREATE TABLE testabc
( item CHAR(25)
, qty NUMBER(13,4)
INSERT INTO testabc
VALUES ('Item1',1);
INSERT INTO testabc
VALUES ('Item2',3);
INSERT INTO testabc
VALUES ('Item3',1);
INSERT INTO testabc
VALUES ('Item4',2); Desired results:
ITEM QTY
Item1 1.000
Item2 3.000
--blank row
--blank row
Item3 1.000
Item4 2.000
--blank rowAnd the solution:
SELECT CASE
WHEN c.n = 1 THEN t.item
END AS item_col
, CASE
WHEN c.n = 1 THEN t.qty
END AS qty
FROM testabc t
SELECT ROWNUM AS n
FROM all_objects
WHERE ROWNUM <= 10 -- If you know an upper bound
) c
WHERE c.n <= t.qty
ORDER BY t.item
, c.n
;Now, it turns out there are only some items which need these extra rows, but I'm not sure if it's possible to only include extra rows for certain items or not...
Here's my new sample data:
CREATE TABLE testabc1
( s CHAR(1)
, item CHAR(25)
, qty NUMBER(13,4)
INSERT INTO testabc1
VALUES ('*','Item1',1);
INSERT INTO testabc1
VALUES ('','Item2',3);
INSERT INTO testabc1
VALUES ('*','Item3',3);
INSERT INTO testabc1
VALUES ('*','Item4',2);And my new desired results: (any row with an asterisk gets extra rows, if the qty is greater than 1)
S ITEM QTY
* Item1 1.000
Item2 3.000
* Item3 3.000
--blank row
--blank row
* Item4 2.000
--blank rowEdited by: user11033437 on Jan 3, 2012 9:27 AM (fixed missing asterisk in desired results)Hi,
Here's a slightly simpler way:
SELECT CASE
WHEN c.n = 1 THEN t.item
END AS item_col
, CASE
WHEN c.n = 1 THEN t.qty
END AS qty
FROM testabc1 t
SELECT ROWNUM AS n
FROM all_objects
WHERE ROWNUM <= 10 -- If you know an upper bound
) c
WHERE c.n <= CASE
WHEN t.s = '*'
THEN t.qty
ELSE 1
END
ORDER BY t.item
, c.n
;This is just like the previous solution, except that the WHERE clause, which was originally
WHERE c.n <= t.qtyis now
WHERE c.n <= CASE ... END
user11033437 wrote:... And my new desired results: (any row with an asterisk gets extra rows, if the qty is greater than 1)
S ITEM QTY
* Item1 1.000
Item2 3.000
Item3 3.000
--blank row
--blank row
* Item4 2.000
--blank row
S should be '*' on the output row where item='Item3', right?
I'm sure you know how to get the s column in the output, but, since I've already tried it:
SELECT CASE
WHEN c.n = 1 THEN '*'
END AS s
, CASE
WHEN c.n = 1 THEN t.item
END AS item_col
, CASE
WHEN c.n = 1 THEN t.qty
END AS qty
FROM testabc1 t
SELECT ROWNUM AS n
FROM all_objects
WHERE ROWNUM <= 10 -- If you know an upper bound
) c
WHERE c.n <= CASE
WHEN t.s = '*'
THEN t.qty
ELSE 1
END
ORDER BY t.item
, c.n
;Edited by: Frank Kulash on Jan 3, 2012 11:11 AM -
Counting rows based on a column value
Tricky Query.No offence if this is a repeat please.
This is a PROD issue in SYBASE.
TableA has id_flag_listing column
TableA
id_flag_listing
N
N
N
N
N
1) If all rows are set to 'N',then my count should be 0.
PrimaryListing
0
2) If there is one row which is 'Y' then this shoud be:
id_flag_listing
N
N
Y
N
N
PrimaryListing
1
How can I count in this manner?
Do i use decode? I am using
Select sum(decode(flg_active),'Y',1,0))
from TABLEA
Will the above work.??
I am using SQL for Sybase.
Please guide?Did you even tried the SQL query I've given?
Your table A
SQL> SELECT flg_listing
2 FROM
3 (
4 SELECT 'N' flg_listing FROM DUAL
5 UNION ALL
6 SELECT 'N' FROM DUAL
7 UNION ALL
8 SELECT 'N' FROM DUAL
9 UNION ALL
10 SELECT 'N' FROM DUAL
11 UNION ALL
12 SELECT 'N' FROM DUAL
13 ) TABLEA;
FLG_LISTING
N
N
N
N
N
Your table A, from which I count where are of 'Y' value. In these queries, I change TableA contents.
SQL> SELECT count(*)
2 FROM
3 (
4 SELECT 'N' flg_listing FROM DUAL
5 UNION ALL
6 SELECT 'N' FROM DUAL
7 UNION ALL
8 SELECT 'N' FROM DUAL
9 UNION ALL
10 SELECT 'N' FROM DUAL
11 UNION ALL
12 SELECT 'N' FROM DUAL
13 ) TABLEA
14 WHERE flg_listing = 'Y';
COUNT(*)
0
SQL> SELECT count(*)
2 FROM
3 (
4 SELECT 'N' flg_listing FROM DUAL
5 UNION ALL
6 SELECT 'N' FROM DUAL
7 UNION ALL
8 SELECT 'Y' FROM DUAL
9 UNION ALL
10 SELECT 'N' FROM DUAL
11 UNION ALL
12 SELECT 'N' FROM DUAL
13 ) TABLEA
14 WHERE flg_listing = 'Y';
COUNT(*)
1
SQL> SELECT count(*)
2 FROM
3 (
4 SELECT 'N' flg_listing FROM DUAL
5 UNION ALL
6 SELECT 'N' FROM DUAL
7 UNION ALL
8 SELECT 'Y' FROM DUAL
9 UNION ALL
10 SELECT 'Y' FROM DUAL
11 UNION ALL
12 SELECT 'Y' FROM DUAL
13 ) TABLEA
14 WHERE flg_listing = 'Y';
COUNT(*)
3Yoann. -
Selecting rows based on one column change
Hi All -
I need to select the rows from a table (this table has 4 columns and has a primary key and have many records for that primary key).
I need to select all the rows for this primary key for which only one column (in this case "flag" column) has been changing from its past value.
How can I do this?
for example, table data is:
ID, flag, Profile,date
pk, Y, Profile4,01/10/10
pk, N, Profile4, 01/08/10
pk,N, Profile3, 01/07/10
pk,Y, Profile3, 01/05/10
pk,Y, Profile2, 01/03/10
pk,N, Profile1, 01/02/10
The output of the query I am looking for should return the following i.e. only retrieve rows whose previous flag value has been changed:
ID, flag, Profile,date
pk, Y, Profile4,01/10/10
pk,N, Profile3, 01/07/10
pk,Y, Profile2, 01/03/10
pk,N, Profile1, 01/02/10
Please share your expertise.
Thanks,
SeenuHi, Seenu,
Centinul wrote:
It is always helpful to provide the following:
1. Oracle version (SELECT * FROM V$VERSION)
2. Sample data in the form of CREATE / INSERT statements.
3. Expected output
4. Explanation of expected output (A.K.A. "business logic")
5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
Seenu001 wrote:(1) Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Solaris: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production Good!
(2) select 'pk' id,'Y' flag,'Profile4' profile,to_date('01/10/10','mm/dd/yy') dt from dual union all
select 'pk','N','Profile4',to_date('01/08/10','mm/dd/yy') from dual union all
select 'pk','N','Profile3',to_date('01/07/10','mm/dd/yy') from dual union all
select 'pk','Y','Profile3',to_date('01/05/10','mm/dd/yy') from dual union all
select 'pk','Y','Profile2',to_date('01/03/10','mm/dd/yy') from dual union all
select 'pk','N','Profile1',to_date('01/02/10','mm/dd/yy') from dualNot bad. It can be made into a CREATE TABLE AS statement without a lot of work, but if you're not willing to do that little bit or work, why should anyone else?
(3) Expected output: I want all the rows from this table where the flags have been changed from its previous value.That's a vague description. Post the exat output, like Solomon did:
ID F PROFILE DT
pk N Profile1 01/02/2010
pk Y Profile2 01/03/2010
pk N Profile3 01/07/2010
pk Y Profile4 01/10/2010
(4) I want all the rows from this table where the flags have been changed from its previous value.That's a repeat of the vague description. Explain how you get the crorrect results, with specific examples, like this:
"The row dated January 2 should be included, because it is the oldest row in the table, regardless of what its flag is.
The row dated January 3 should be included because ...
The row dated January 5 should *not* be included, because ..."
You don't have to explain every row, just every reason.
Solomon - I tried your query but the prev_flag is not being populated, it shows null value '-'NULL is not the same as '-'. Did you issue a command like
SET NULL "-"that would display a '-' instead of NULL?
Solomon's query works fine for me, as it did for him. Post your code, even if you just copied it from this site. (There may have been an editing problem.)
Frank - I tried your query, prev_flag is populated in this case but when I am using with the WITH clause, I am getting an error saying "unsupported column aliasing" , I guess WITH command doesnt allow use of column alias. The problem is that I forgot the keyword AS after the sub-query name.
WITH got_prev_flag AS
SELECT id, flag, profile, dt -- DATE is not a good column name
, LAG (flag, 1, '??') OVER (ORDER BY dt) AS prev_flag
FROM t
-- WHERE ... -- any filtering goes here
SELECT id, flag, profile, dt
FROM got_prev_flag
WHERE flag != prev_flag
;If you don't post data in an executable form, then people can't test their ideas. If people can't test their ideas, trivial mistakes like this are very likely.
This flag column will have either
Y or N columns. Could you tell me what is the use of "??" value.By default, LAG returns NULL for the first row. If you want to include the first row in the results, then "WHERE flag != prev_flag" won't work when prev_flag is NULL. We could explicitly check for "prev_flag IS NULL", but I find it cleared to override the default, and have LAG return '??' on the first row. I guessed that '??' would make the condition "WHERE flag != prev_flag" work, no matter what value flag had. There's nothing magical about '??'; you can use any string that will never actually match flag. -
Compare two tables having different number of rows based on 2 columns
Hi,
I am having two tables table a having field1, field2 and table b having fields field1 and field2.
I want those records from table a in which field1 of table a is not matching to field1 of table b and field2 of table b not matching to field2 of table b, but i also want the bifurcation of records as whether field 1 is not matching, field 2 is not matching or both fields 1 & 2 are not matching.
e.g.
table a table b
field1 field2 field1 field2
1 6 12 5
2 5 1 9
13 51 13 51
45 31 99 121
33 45
In this case my output should be
table a
field1 field2 Mtchng_Field
1 6 Field 2 not mtchng
2 5 Field 1 not mtchng
45 31 Feild1 and Field2 both not matching
How would i get my result in the required format.sql>select * from t1;
N1 N2
1 6
2 5
13 51
45 31
33 45
sql>select * from t2;
N1 N2
12 5
1 9
13 51
99 121
sql>
select n1,n2,decode(nvl(p1,0)+nvl(p2,0),0,'No match',1,'F2 not match',2,'F1 not match','Match') status
from(
select n1,n2,(select 1
from t2 where n1=t1.n1) p1,(select 2
from t2 where n2=t1.n2) p2
from t1);
N1 N2 STATUS
1 6 F2 not match
2 5 F1 not match
13 51 Match
45 31 No match
33 45 No match
Message was edited by:
jeneesh
Message was edited by:
jeneesh
Some problems... -
Selecting top 10 rows based on one column.
Hi,
I need to display the top 10 records for each distinct value of a column.USE Northwind;
-- Solution 1
SELECT S.SupplierID, S.CompanyName, CA.ProductID, CA.UnitPrice
FROM dbo.Suppliers AS S
CROSS APPLY
(SELECT TOP (10) *
FROM dbo.Products AS P
WHERE P.SupplierID = S.SupplierID
ORDER BY UnitPrice DESC, ProductID DESC) AS CA
ORDER BY S.SupplierID, CA.UnitPrice DESC, CA.ProductID DESC;
-- Solution 2
WITH C AS
SELECT S.SupplierID, S.CompanyName, P.ProductID, P.UnitPrice,
ROW_NUMBER() OVER(
PARTITION BY P.SupplierID
ORDER BY P.UnitPrice DESC, P.ProductID DESC) AS RowNum
FROM dbo.Suppliers AS S
JOIN dbo.Products AS P
ON P.SupplierID = S.SupplierID
SELECT SupplierID, CompanyName, ProductID, UnitPrice
FROM C
WHERE RowNum <= 10
ORDER BY SupplierID, ProductID DESC, UnitPrice DESC;
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Maybe you are looking for
-
I have gifted itunes cards to family members once before. Now when I try to send them, after I use my apple ID, select amount, go through all the steps and password, and click buy now....a window comes up telling me it can't be sent, to contact supp
-
Calling a javascript function from Flash
Maybe someone out there can help? I'm trying to set a variable in AS3 and then use an event to call that variable. The links are set in an xml file. I have it working with hyperlinks using navigateToURL, but it's not doing exactly what I want. Wh
-
Hi, I knew that all apps after buying them could be downoad to other Apple's devices. The last week I bought Keynote for the iPad and I need for my Mac too, but I don't know why I can't download it. Shoul I buy Keynote for the Mac too? Is the same wi
-
Elements 12 Editor stopped working message
I keep getting a "Photoshop Elements 12 Editor has stopped working" message when I try to go to edit
-
Reverse sync, load music from ipod to puter
hi, i got some bad-arse malware on my puter, i backed up my hard drive to external and did complete revovery (system reload). the backup copied the path n folders but none of the music!!! (so if u do bakup, chek 2c if music copied!)(i have bout $100