I need to transpose rows in to columns from table A to table B in MS Access 2007.
Here we go, Below is the data in Table01 which should be transposed to another table.
Customer_Name Contacted_Date Response_Code
Mr. Abc 01-Sep-12 Switched Off
Mr. Abc 02-Sep-12 Ringing
Mr. Abc 03-Sep-12 Call Back
Mr. Abc 04-Sep-12 Agreed
Mr. Def 01-Sep-12 Switched Off
Mr. Def 02-Sep-12 Ringing
Mr. Def 03-Sep-12 Call Back
Mr. Def 04-Sep-12 Agreed
Mrs. Ghi 01-Sep-12 Switched Off
Mrs. Ghi 02-Sep-12 Ringing
Mrs. Ghi 03-Sep-12 Call Back
Mrs. Ghi 04-Sep-12 Agreed
Mr. Jkl 01-Sep-12 Switched Off
Mr. Jkl 02-Sep-12 Ringing
Mr. Jkl 03-Sep-12 Call Back
Mr. Jkl 04-Sep-12 Agreed
Mr. Mno 01-Sep-12 Switched Off
Mr. Mno 02-Sep-12 Ringing
Mr. Mno 03-Sep-12 Call Back
Mr. Mno 04-Sep-12 Agreed
Mrs. Pqr 01-Sep-12 Switched Off
Mrs. Pqr 02-Sep-12 Ringing
Mrs. Pqr 03-Sep-12 Call Back
Mrs. Pqr 04-Sep-12 Agreed
Here is the exact thing what i need.
Customer_Name 01-Sep-12 02-Sep-12 03-Sep-12 04-Sep-12
Mr. Abc Switched Off Ringing Call Back Agreed
Mr. Def Switched Off Ringing Call Back Agreed
Mrs. Ghi Switched Off Ringing Call Back Agreed
Mr. Jkl Switched Off Ringing Call Back Agreed
Mr. Mno Switched Off Ringing Call Back Agreed
Mrs. Pq Switched Off Ringing Call Back Agreed
So, the data is transposed in to a separate table called as Table02.
Related
There is a table that looks like below. I want to match sender's and receiver's names. In this example, I'm only interested in ABC and DEF as their names match (not a complete match but that is ok). How do I extract cases similar to ABC and DEF?
Table A:
id
sender full name
receiver first name
receiver last name
ABC
mike smith brown
mike
smith
DEF
kate josefin baker
kate
baker williams
GHI
kim jones
nathan
wilson
My objective is to make a table in Hive wherein for every new value of a column, say name, it will seed a word.
any code sample that can do this?
expected result:
name
transaction date
transaction code
Karen
01012021
ABC
Karen
01022021
DEF
Karen
01032021
ABC
Karen
01042021
GHI
name
transaction_date
transaction_code
Gilbert
01012021
ABC
Gilbert
01022021
DEF
Gilbert
01032021
ABC
Gilbert
01042021
GHI
name
transaction_date
transaction_code
Sherwin
01012021
ABC
Sherwin
01022021
DEF
Sherwin
01032021
ABC
Sherwin
01042021
GHI
You can find distinct name (create a view or table)
Loop through each value
2a) As you are looping make a insert "name" | transation_Date | code
Not sure if you can do alone in Hive but with a combination of Python/Spark/Scala you can do this. Hope it helps in some ways.
I have a file containing data in following format:
abc 123 456
cde 45 32
efg 322 654
abc 445 856
cde 65 21
efg 147 384
abc 815 078
efg 843 286
and so on.
How can transpose it into following format using pig:
abc 123 456 cde 45 32 efg 322 654
abc 445 856 cde 65 21 efg 147 348
abc 815 078 efg 843 286
Also, in case cde is missing after abc, it should insert blank spaces instead, since it is a fixed width file.
I tried grouping but it ain't worked for me.
Well, you can do it by writing custom loader. The easiest attempt is to extend PigStorage and override getNext() method making it call record reader three times, instead of 1 and produce unioned Tuple.
I'm working on following scenario in SAS.
Input 1
AccountNumber Loans
123 abc, def, ghi
456 jkl, mnopqr, stuv
789 w, xyz
Output 1
AccountNumbers Loans
123 abc
123 def
123 ghi
456 jkl
456 mnopqr
456 stuv
789 w
789 xyz
Input 2
AccountNumbers Loans
123 15-abc
123 15-def
123 15-ghi
456 99-jkl
456 99-mnopqr
456 99-stuv
789 77-w
789 77-xyz
Output 2
AccountNumber Loans
123 15-abc, 15-def, 15-ghi
456 99-jkl, 99-mnopqr, 99-stuv
789 77-w, 77-xyz
I manged to get Input 2 from output 1, just need Output 2 now.
I will really appreciate the help.
Thanks!
Try this, replacing [Input 2] with the actual name of your Input 2 table.
data output2 (drop=loans);
do until (last.accountnumbers);
set [Input 2];
by accountnumbers;
length loans_combined $100;
loans_combined=catx(', ',loans_combined,loans);
end;
run;
![Cognost reports studio Query Explorer]
Below is the snapshot of a table.
**Acctno ClientNo ClientName PrimaryOffId SecondaryOffID**
101 11111 ABC corp 3 Not Defined
102 11116 XYZ Inc 5 Not Defined
103 11113 PQRS Corp 2 9
104 55555 Food LLC 4 11
105 99999 Kwlg Co 1 Not Defined
106 99999 Kwlg Co 1 Not Defined
107 11112 LMN Corp Not Defined 6
108 11112 LMN Corp Not Defined 6
109 11115 Sleep Co 4 10
110 44444 Cool Co Not Defined 8
111 11114 Sail LLC 3 Not Defined
112 66666 Fun Inc 1 Not Defined
113 88888 Job LLC 5 12
114 22222 Acc Co Not Defined Not Defined
115 77777 Good Corp 2 Not Defined
116 33333 City LLC Not Defined 7
117 33333 City LLC Not Defined 7
118 33333 City LLC Not Defined 7
119 11111 ABC corp 3 Not Defined
I want to replace PrimaryOffID and SecondaryOffID with their Names coming from this table
EmpID Names
1 Cathy
2 Chris
3 John
4 Kevin
5 Mark
6 Celine
7 Jane
8 Phil
9 Jess
10 Jose
11 Nick
12 Rosy
The Result should look like this: Notice that, If Cathy is the PrimaryOfficer, she can't be the Secondary Officer and vice versa. This logic is applicable for all the Names
Acctno ClientNo Client Name PrimOffName SecondaryOffName
101 11111 ABC corp John Not Defined
102 11116 XYZ Inc Mark Not Defined
103 11113 PQRS Corp Chris Jess
104 55555 Food LLC Kevin Nick
105 99999 Kwlg Co Cathy Not Defined
106 99999 Kwlg Co Cathy Not Defined
107 11112 LMN Corp Not Defined Celine
108 11112 LMN Corp Not Defined Celine
109 11115 Sleep Co Kevin Jose
110 44444 Cool Co Not Defined Phil
111 11114 Sail LLC John Not Defined
112 66666 Fun Inc Cathy Not Defined
113 88888 Job LLC Mark Rosy
114 22222 Acc Co Not Defined Not Defined
115 77777 Good Corp Chris Not Defined
116 33333 City LLC Not Defined Jane
117 33333 City LLC Not Defined Jane
118 33333 City LLC Not Defined Jane
119 11111 ABC corp John Not Defined
But Instead it looks like this:
Acctno ClientNo ClientName PrimOffName SecondaryOffName
101 11111 ABC corp John Not Defined
102 11116 XYZ Inc Mark Not Defined
103 11113 PQRS Corp Chris Not Defined
103 11113 PQRS Corp Not Defined Jess
104 55555 Food LLC Kevin Not Defined
104 55555 Food LLC Not Defined Nick
105 99999 Kwlg Co Cathy Not Defined
106 99999 Kwlg Co Cathy Not Defined
107 11112 LMN Corp Not Defined Celine
108 11112 LMN Corp Not Defined Celine
109 11115 Sleep Co Kevin Not Defined
109 11115 Sleep Co Not Defined Jose
110 44444 Cool Co Not Defined Phil
111 11114 Sail LLC John Not Defined
112 66666 Fun Inc Cathy Not Defined
113 88888 Job LLC Mark Not Defined
113 88888 Job LLC Not Defined Rosy
114 22222 Acc Co Not Defined Not Defined
115 77777 Good Corp Chris Not Defined
116 33333 City LLC Not Defined jane
117 33333 City LLC Not Defined jane
118 33333 City LLC Not Defined jane
119 11111 ABC corp John Not Defined
Notice that, now the Acctno is no more unique, Where ever the Names should have been in both the fields together, it separates and gives the output in the next row creating multiple records. i tried various options but it didn't work. Please be aware, that I am creating this report in Cognos Studio. Please suggest the possible query to get the desired result. Thanks in Advance. Appreciate your help.
You don't state which version of Cognos you're using. "Cognos Studio" is ambiguous. I'm most familiar with 8.4.1, but even then you don't say if you're trying to define this in the Cognos model, Query Studio, Event Studio or Report Studio.
Second, you should always show what you've got so far when asking questions on StackOverflow. People want to see what you have done to show you want to fix, not repeat the lion's share of the work. That's why you got downvotes.
As far as plain SQL, you'll want to do this:
SELECT a.Acctno, a.ClientNo, a.ClientName, coalesce(e1.Names,'Not Defined') "PrimaryOffName", coalesce(e2.Names,'Not Defined') "SecondaryOffName"
FROM Account a
LEFT OUTER JOIN Emp e1
ON t.PrimaryOffID = e1.EmpID
LEFT OUTER JOIN Emp e2
ON t.PrimaryOffID = e2.EmpID
I made up table names. You can do this in Report Studio by creating two queries for Emp and outer joining them in succession to the Account query.
If you're able to, you'll want to move the OffID fields to a separate juntion table and remove them from the Account table. You can then create a Status field or flag in that junction table that identifies primary and secondary.