Compare two tables based on two columns
Hi,
my tables looks like this:
Desc Table A (account)
Account1_id
Account2_id
name,
empid
Table B (Bill )
BillNo
Advertiserid
agencyid
total vvalue
I need to pick up total value from table B where the unique combination of advertiser-Agency id is the same as the given account1_id -Account2_id combination in table A for each employee id.
In other words my output should be like
Empid | Account_id (should be same as advertiserid)| Account2_id (same as agencyid) | sum(total_value) for this adv-agency combination.....
objective: Get the total value from table B for each unique account1-account2 combination (advertiser-agency in other words) .
I am not sure if I should use a coreelated subquery or how to handle the situation....Right now I am just checking the two columns separately like this:
select.......from a,b
where b.advertiser_id = a.account1_id and b.agencyid = b.account2id
Is it correct to do so? I have a feeling that I am missing something if I join them seperately like this......Any advice on this?
I am using Oracle 10g. Hope I am clear.Please let me know. Thankx in advance.
Here you go:
SQL> WITH bill AS
2 (
3 SELECT 1000 AS billno, 101 AS advertiserid, 102 AS agencyid, 5000 AS total_value FROM DUAL UNION ALL
4 SELECT 1001, 101, 103, 5000 FROM DUAL UNION ALL
5 SELECT 1002, 101, 102, 1000 FROM DUAL
6 ), account AS
7 (
8 SELECT 101 AS account1_id, 102 AS account2_id, 'John' AS name, 50 AS empid FROM DUAL UNION ALL
9 SELECT 101, 103, 'James', 40 FROM DUAL UNION ALL
10 SELECT 101, 105, 'Joe', 60 FROM DUAL
11 )
12 /* End Sample Data */
13 SELECT a.name
14 , a.empid
15 , a.account1_id
16 , a.account2_id
17 , SUM(b.total_value)
18 FROM account a
19 JOIN bill b ON a.account1_id = b.advertiserid
20 AND a.account2_id = b.agencyid
21 GROUP BY a.name
22 , a.empid
23 , a.account1_id
24 , a.account2_id
25 ;
NAME EMPID ACCOUNT1_ID ACCOUNT2_ID SUM(B.TOTAL_VALUE)
John 50 101 102 6000
James 40 101 103 5000
Similar Messages
-
Cartesian of data from two tables with no matching columns
Hello,
I was wondering – what’s the best way to create a Cartesian of data from two tables with no matching columns in such a way, so that there will be only a single SQL query generated?
I am thinking about something like:
for $COUNTRY in ns0: COUNTRY ()
for $PROD in ns1:PROD()
return <Results>
<COUNTRY> {fn:data($COUNTRY/COUNTRY_NAME)} </COUNTRY>
<PROD> {fn:data($PROD/PROD_NAME)} </PROD>
</Results>
And the expected result is combination of all COUNTRY_NAMEs with all PROD_NAMEs.
What I’ve noticed when checking query plan is that DSP will execute two queries to have the results – one for COUNTRY_NAME and another one for PROD_NAME. Which in general results in not the best performance ;-)
What I’ve noticed also is that when I add something like:
where COUNTRY_NAME != PROD_NAME
everything is ok and there is only one query created (it's red in the Query plan, but still it's ok from my pov). Still it looks to me more like a workaround, not a real best approach. I may be wrong though...
So the question is – what’s the suggested approach for such queries?
Thanks,
Leszek
Edited by xnts at 11/19/2007 10:54 AMWhich in general results in not the best performanceI disagree. Only for two tables with very few rows, would a single sql statement give better performance.
Suppose there are 10,000 rows in each table - the cross-product will result in 100 million rows. Sounds like a bad idea. For this reason, DSP will not push a cross-product to a database. It will get the rows from each table in separate sql statements (retrieving only 20,000 rows) and then produce the cross-product itself.
If you want to execute sql with cross-products, you can create a sql-statement based dataservice. I recommend against doing so. -
Spliting a table in to two table based on the groups in SSRS
Hi,
I am trying to a split a rows accross two tables based on a group.
So far I have added a list and added a row group and grouped it using lineof business
Inside my list i have two identical tables so i can display the data
for the first table i have set the row visibility as follows: where LineOfbusiness1 is the groupname of my list group
=RowNumber(Nothing) >= (IIf(CountRows("LineOfBusiness1")\2 = 1, CountRows("LineOfBusiness1")/2, (CountRows("LineOfBusiness1")/2)+1))
and for the second table in the i have set the row visibility as follows
=RowNumber(Nothing)< (IIf(CountRows("LineOfBusiness1")\2 = 1,CountRows("LineOfBusiness1")/2, (CountRows("LineOfBusiness1")/2)+1))
this set up works fine for the first group but it doesnt display the data the way i want for the subsequent groups.
so how do i have the table start over after each group... plus in my group i have specified to do a page break after everygroup...
Any help will be appreciated.
Thanks
KarenVisakh,
Thanks for answering.... a sample for the data will look like
dataset----
create table #dataset
Code varchar(5),
Name varchar(200),
Lineofbusiness int,
Statename varchar(10),
typed int,
description varchar(2000)
insert into #dataset
select 45111,abc,1,AL,4500,policies
insert into #dataset
select 45111,abc,1,AL,2500,vehiles
insert into #dataset
select 45111,abc,1,AL,3,drivers
insert into #dataset
select 45000,bca,2,AL,4500,policies
insert into #dataset
select 45000,bca,2,AL,500,house
insert into #dataset
select 45000,bca,2,AL,40,theft
When i display the data i want it to be
Line of business 1
policies 4500 drviers 3
vehiles 2500
Line of business 2
Policies 4500 theft 40
House 500
but right now the for lineofbusiness 1 its showing the correct way for but the line 2 everything is being displayed in the right.
Thanks
Karen -
Combining two tables without any distinct columns between them
Folks,
Hi sidy2j,
According to your description, we need to verify your table structures, and the actual results which you want to get from your tables. Please post more information for analysis.
Assume, if you want to a one to one record mapping between two tables without any common column between them for joining, you can refer to the following scripts to implement your requirement. For more information, see:
http://sqlhints.com/2013/09/07/joining-two-tables-without-any-common-column-between-them-sql-server/
If you want to match every row in the first table with every row in the second table, you can refer to the following detail.
http://stackoverflow.com/questions/1198124/combine-two-tables-that-have-no-common-fields
Hope it can help you.
Regards,
Sofiya Li
Sofiya Li
TechNet Community Support -
Sum the value of look up table based on two filter criteria
Hello Everyone
I am new to Powerpivot and would appreciate if someone could help me on the following problem.
You can download the example of this excel file form the following DropBox link:
Dropbox Link
The first table is tOrders
Week number
Work center
order number
Production time in minutes
2
a
111
60
2
a
112
70
2
b
113
60
3
b
114
50
3
a
115
40
3
b
116
60
4
a
117
90
4
b
118
40
The second is dLookupList
Week number
Work center
mantenace in minutes per week
Break dows in minutes per week
2
a
10
10
2
b
20
5
3
a
15
12
3
b
30
10
4
a
20
10
4
b
10
10
I’m trying to create Pivot that has filter on Week number to show the number of orders, Sum of Production time in minutes and the total of the values form the lookup table dLookupList that matches the work center and the selected week
numbers. So that I can calculate the total time for each work center. Filter criteria is Week number and Work center.
For example if someone select all weeks numbers the result sould look like this
Week number
(All)
Work center
Count of order number
Sum of Production time in minutes
mantenace in minutes per week
Break dows in minutes per week
Total time
a
4
260
45
32
337
b
4
210
60
25
295
Grand Total
8
470
Result for week 2
Week number
2
Work center
Count of order number
Sum of Production time in minutes
mantenace in minutes per week
Break dows in minutes per week
Total time
a
2
130
10
10
150
b
1
60
20
5
85
Grand Total
3
190
How can I relate these two tables to get the above result?
Any help is highly appreciated.
Regards
PriyanHi Recio
Thank you very much for the swift response. I was able to get it work.
I got two questions:
How do you add a total time column to the pivot table like you did? Because there are no calculated field in power pivot.
I prefer that the filter is based on the Orders table. So that if you select all Week numbers in the filter, that pivot will show result for all orders and relevant sums from the lookup list.
Link download the example file
For example: I add Week number 5 to the work center “a”
Week number
Work center
WNandWC
mantenace in minutes per week
Break dows in minutes per week
2
a
WN2WCa
10
10
2
b
WN2WCb
20
5
3
a
WN3WCa
15
12
3
b
WN3WCb
30
10
4
a
WN4WCa
20
10
4
b
WN4WCb
10
10
5
a
WN5WCa
1
1
In the orders table there are no records for week number 5
Week number
Work center
WNandWC
order number
Production time in minutes
2
a
WN2WCa
111
60
2
a
WN2WCa
112
70
2
b
WN2WCb
113
60
3
b
WN3WCb
114
50
3
a
WN3WCa
115
40
3
b
WN3WCb
116
60
4
a
WN4WCa
117
90
4
b
WN4WCb
118
40
4
a
WN4WCa
119
50
But the pivot sums up the week number 5 also.
Do you have any idea how to solve it?
Thank you very much.
Regards
Priyan -
Trying to use ALL_TAB_COLS to find two tables based on input rows
I'm using 9i.
I'm trying to use the ALL_TAB_COLS table to find two tables that contain columns I can join them on. I know the names of the two tables. We can call them table1 and table2. I just using the columns that are stored in them below to find a common set of tables.
The query I'm using is the following
select distinct did.TABLE_NAME, did.COLUMN_NAME
from
(Select * from ALL_TAB_COLS
where column_name in('SO_LINE_ID','SO_LINE_NUMBER', 'SO_ORDER_NUMBER', 'SO_HEADER_ID','AR_CUSTOMER_TRX_LINE_ID')
--and OWNER = 'FTBV'
) did
join
(Select * from ALL_TAB_COLS
where column_name in('SCHED_DISTRIBUTION_ID', 'CODE_COMBINATION_ID', 'PRODUCT_BUSINESS_CODE', 'PRODUCT_GROUP_CODE', 'PRODUCT_CODE')
--and OWNER = 'FTBV'
) iii
on did.TABLE_NAME = iii.TABLE_NAME;It's giving me limited results.
What I need is something that can find interim tables that would link my two tables together based on the unique columns I've provided. Does such a query exist?
Thanks in Advance.Only if there is a defined foreign key relationship. If there is one the queries you want are on the Constraints page of Morgan's Library at www.psoug.org. If they do not exist then you need to find a subject matter expert that can explain the application's design.
The fact that you are asking this question is a strong indication of a lack of proper documentation at your facility: Something you might wish to address. -
Join Two tables based on TO_DATE,TRIM,UPPER Functions in RPD
Hi All,
I have a requirement where I have to join 2 tables based on the functions TO_DATE,TRIM,UPPER.
I have Date Of Birth, Person Name . So I have to use these functions and then join in the RPD.
Is it possible to achieve. I am stuck in this problem.
Regards,
KrishnaHi Dann,
Thanks for your reply. I had tried adding these functions but I get the error 'Only columns,designated predicates and operators are allowed". Niether in the Business not in the Physical layer we are allowed
to enter any functions in the join conditions between the two tables.
I am not very sure whether this is the normal behaviour or I can avoid this by doing something.
Thanks,
Krishna -
Merge Two Tables with the same columns but different data
I have a table that has the following columns:
Current Table Definition
commonname
family
genus
species
subspecies
code
I have a number of entries that donât fit the current table definition â that is that they only have a common name or description and a code. These records donât actually represent a species but are needed for data entry because they represent an object that may be encountered in the study (Bare Ground â which isnât a species but would need to be recorded if encountered). So I would really like 2 tables:
Table 1 Miscellaneous
name
code
Table 2 Plant Species
commonname
family
genus
species
subspecies
code
I would like two tables so I can enforce certain constraints on my species table like requiring that the family, genus, species, subspecies combination is unique. I canât do this if I have all the âotherâ records that donât have a family, genus, species, or subspecies unless I put in a lot of dummy data into the fields to make each record unique. I donât really want to do this because these miscellaneous records really donât represent a specific species.
So â the problem is that while I want this data separate I will need to point a column from another table to the code column in both tables.
How is this best done? Table? View? Merge?Hi,
Actually you don't have to use scope refs. Sorry but I misunderstood you earlier. Here is a complete example that does exactly what you want. Notice how I added the constraint to the materialized view. Also notice when we try to insert a code in tbl3 that doesn't exist in the view, we get an error. HTH.
SQL> create table tbl1 (name varchar2(10), code varchar2(3) primary key);
Table created.
SQL> create table tbl2 (commonname varchar2(10), code varchar2(3) primary key);
Table created.
SQL> insert into tbl1 values ('n1','c1');
1 row created.
SQL> insert into tbl1 values ('n2','c2');
1 row created.
SQL> insert into tbl1 values ('n3','c3');
1 row created.
SQL> insert into tbl2 values ('name1','c1');
1 row created.
SQL> insert into tbl2 values ('name2','c2');
1 row created.
SQL> insert into tbl2 values ('name3','c3');
1 row created.
SQL> commit;
Commit complete.
SQL> create materialized view view1 as select name, commonname, tbl1.code from tbl1, tbl2 where tbl1.code = tbl2.code;
Materialized view created.
SQL> select * from view1;
NAME COMMONNAME COD
n1 name1 c1
n2 name2 c2
n3 name3 c3
SQL> create table tbl3 (code varchar2(3), record varchar2(1));
Table created.
SQL> alter table view1 add constraint view1pk primary key (code); -- <-Note how I added a constraint to the view
Table altered.
SQL> alter table tbl3 add constraint tbl3fk foreign key (code) references view1(code);
Table altered.
SQL> insert into tbl3 values ('c1','r');
1 row created.
SQL> insert into tbl3 values ('c99','r');
insert into tbl3 values ('c99','r')
ERROR at line 1:
ORA-02291: integrity constraint (RAJS.TBL3FK) violated - parent key not found
SQL> spool of;
-Raj Suchak
[email protected] -
Joining Two Tables with a DISTINCT column value
I have two tables I need to join, but the 'left' table I only need DISTINCT for a column.
create table t1
bid number(8),
b_number number(8),
dset varchar2(20),
misc varchar2(20)
create table t2
cid number(8),
track number(8)
select bid, cid
from ( select bid, b_number
from t1
where dset = 'ABC1234'
and misc = 'TEXT'
) x,
( select cid, track
from t2
where exists ( select 1 from t2 where t2.track = t1.b_number )
) z
where x.b_number = z.trackI only need records with DISTINCT cid values, but I keep getting multiple instanced of cid.
Any suggestions?
Thanks!Maybe this?
select distinct cid
from t2
where track in
select b_number
from t1
where dset = 'ABC1234'
and misc = 'TEXT'
) -
How to join two tables with no similar columns
Hi all,
I have two tables as follows:
Table T1 have Attributes as follows:
GLCODE,
BRANCH,
ITEM_NUMBER,
DEMAND_DATE,
QUANTITY,
SOURCE
Table T2 have Attributes as follows:
FORECAST_DATE
Now in SQL if run the following stattement iam getting out put.
SELECT GLCODE,BRANCH,ITEM_NUMBER,DEMAND_DATE,QUANTITY, SOURCE,(SELECT DISTINCT FORECAST_DATE FROM T2) FROM T1
The above SQL Statement giving correct results for me.
The same SQL Statement how can we implement in mapping level?
Regards,
AvaJaap van,
>
You have to specify an outer join, but how do you do that if there is no join to begin with? I would do the following (which I didn't test yet):
add an extra column (say C_JOIN) to the T2-ingroup of the join operator and fill it with from a constant operator with say value 1. Then use T2.C_JOIN (+) = 1 as the join condition.
If every record in T2 is guaranteed to have the same value, instead of using a deduplicator, which will read all records, sort them and deduplicate them, you can use a filter with filter condition ROWNUM < 2, which only will read one record.
I am facing almost the same problem but not entirely thou and I was wondering if you have an idea how to even start.
Problem:
I got this table:SQL> desc ita.tpis32_job_status
Name Null? Type
JOBID NOT NULL NUMBER
T1_ID NUMBER
QID NUMBER
REQ_TYPE VARCHAR2(10)
SUBMIT_TIME DATE
OWNERID VARCHAR2(30)
DESCRIPTION VARCHAR2(150)
STARTTIME DATE
ENDTIME DATE
STATUS VARCHAR2(50)
ERROR_ID NUMBER
TABLE_NAME VARCHAR2(30)
SERVER_ID VARCHAR2(10)
DATABASE VARCHAR2(20)
PRIORITY NUMBER
NUM_LINES NUMBER
PROCESS_ID NUMBER
QUE_TIME NUMBER
STATUS_CODE NUMBER
ERROR_MSG VARCHAR2(500)
NUM_LINES_TS NUMBER
REMOTE_STATUS NUMBER
This the above table, i am looking for JOBID (a five digit number) like 25875.
What I want to do is add or append this five digit number to a string to find the corresponding table in dba_tables or all_tables. The only way I have try to do this is by writing PLSQL as you see from here:
Re: Use PLSQL to delete tables dynamically
When the select is writing properly, the result of the five digit number from JOBID and the string should look like the below result (job_(five digit_%).
My problem is there is no relationship between ALL_TABLES and the my own table (ita.tpis32_job_status). Any help will be appreciated.
TABLE_NAME
JOB_58871_OUTDATA
JOB_58868_TS
JOB_58868_OUTDATA
JOB_58867_TS
JOB_58867_CMDLBL_2
JOB_58867_OUTDATA
JOB_58866_TS -
Find missing values in third table based on two other tables
Hi- I have tried to do this on my own but the answer eludes me. Can someone please point me in a better direction? We have a table project_categories with project_IDs and related project category_IDs. We have another table contact_categories with contact_IDs and related contact category_IDs. We use these two tables to link contacts to projects by at least one category_ID. It works well for email notifications. We have a third table for "planholders" who are interested in particular projects. The planholder table has contact_IDs and related project_IDs. I want to find contacts who have expressed interest in a project, by inserting a row in the planholder table, but they have not selected any of the project categories in contact categories. This would be an unusually rare exception, so to test it I added myself as a contact 100010 and as a project "planholder", but deliberately did not select any of the related project categories in contact categories.
select ph.contact_id, ph.project_id, pc.category_id, cc.category_id
from purchasing_planholder ph, purchasing_project_categories pc, purchasing_contact_categories cc
where ph.project_id=pc.project_id
and ph.contact_id=cc.contact_id
and ph.contact_id||ph.project_id||cc.category_id
not in (select ph.contact_id||pc.project_id||pc.category_id
from purchasing_planholder ph, purchasing_project_categories pc, purchasing_contact_categories cc
where ph.project_id=pc.project_id
and ph.contact_id=cc.contact_id)
and ph.contact_id=100010
This gives me every category for the test contact and every category for the project. I want to find contacts in the planholder table who have not selected any of the categories related to the specific project they selected in the planholder table. I tried minus, outer joins, etc. Does this require PL/SQL and a temp table, or can I find the exceptions with a report? Or do I need a different approach? The ideal answer would display one row with the contact_ID and the project_ID, where the contact has not selected any of the project categories. This would be used to alert them that they need to select at least one of the project categories on the contact form. Thanks for any feedback.
Peter
CONTACT_ID PROJECT_ID CATEGORY_ID CATEGORY_ID
100010 701 1 19
100010 701 1 18
100010 701 16 19
100010 701 16 18
100010 701 21 19
100010 701 21 18
100010 701 24 19
100010 701 24 18
8 rows selectedHi User,
When you Post a Question in Forum, Please be clear of the Inputs to be given, the expected output and the tries you made,
the errors/results you faced.
Also, see this link of BluShadow.
SQL and PL/SQL FAQ
Please enclose the query or programs in code tags for a formatted code.
Just Try something like this,
SELECT *
FROM emp c
WHERE NOT EXISTS (SELECT *
FROM emp a
WHERE EXISTS (SELECT *
FROM emp b
WHERE a.empno = b.empno));In the Inner Query, the conditon checked is empno same in both the tables, and for example some rows are obtained, other than
this rows all other results are obtained from the outer query.
In the above case no rows are returned.
Thanks,
Shankar -
Joining Two Tables based on Conditions.
Hi All,
i would like to join two tables emp and dept with conditional join like
for example: select emp.column1...............
left outer join DEPT ON if Dept.column1='A" then emp.column1=dept.column1
else emp.column2=dept.column3
i know that bu using the UNION we can dothis, but i donot want to USE UNION.
please let me know if any workaround for this.
Thanks,
KalyanSQL> select * from etl
2 /
EMPNO ENAME JOB MGR SAL COMM DEPTNO AAA DEPT_NO
7566 JONES MANAGER 7839 2975 20 2 20
7654 MARTIN SALESMAN 7698 1250 1400 30 3 10
7698 BLAKE MANAGER 7839 2850 30 3 10
7782 CLARK MANAGER 7839 2450 10 1 20
7788 SCOTT ANALYST 7566 3000 20 2 20
7839 KING PRESIDENT 5000 10 1 20
7844 TURNER SALESMAN 7698 1500 30 3 10
7876 ADAMS CLERK 7788 1100 20 2 20
7900 JAMES CLERK 7698 950 30 3 10
7902 FORD ANALYST 7566 3000 20 2 20
7934 MILLER5 CLERK 7782 1300 10 1 20
7936 MILLER7 CLERK 7782 1300 10 1 20
12 rows selected.
SQL> select * from dept;
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> ed
Wrote file afiedt.buf
1 select
2 e.empno,
3 e.ename,
4 e.deptno,
5 aaa,
6 e.dept_no,
7 d.deptno,
8 d.dname
9 from
10 etl e ,
11 dept d
12 where
13 (e.aaa =1 and e.deptno = d.deptno) or
14* (e.aaa =2 and e.dept_no =d.deptno)
SQL> /
EMPNO ENAME DEPTNO AAA DEPT_NO DEPTNO DNAME
7566 JONES 20 2 20 20 RESEARCH
7788 SCOTT 20 2 20 20 RESEARCH
7876 ADAMS 20 2 20 20 RESEARCH
7902 FORD 20 2 20 20 RESEARCH
7782 CLARK 10 1 20 10 ACCOUNTING
7839 KING 10 1 20 10 ACCOUNTING
7934 MILLER5 10 1 20 10 ACCOUNTING
7936 MILLER7 10 1 20 10 ACCOUNTING
8 rows selected.Regards
Singh -
Access data from from two lists based on lookup columns and insert into another
Hi,
I am new in SharePoint and is stuck in some problem.
I want to insert data in to a list by fetching data from 2 lists.
The scenario is :
List A Columns : EmployeeName, EmployeeID, EmployeeSalary
List B Columns : DepartmentName, EmployeeID, ManagerID
EmployeeID is lookup column
I want to fetch data from these 2 lists and insert data into another list:
List C Columns: EmployeeName, EmployeeSalary, DepartmentName
Can someone please explain me all the possible approaches to do the above taskIf ListA and ListB are the lists that you created, it would be better to generate the lists data into one list not seperate lists, as they both represents the property information of one employee.
If they are existing lists, you may have following considerations:
1. if you are a programmer, it would be easier to have a lookup column at ListA, to generate the EmployeeName, EmplyeeSalary, then using ItemAdded event, to generate the DepartmentName column based on EmployeeID column.
2. have a lookup column look at ListA, use workflow, set when item is created, start the workflow automatically, then in the workflow, find ListB related item based on EmployeeID column, to set the DepartmentName column, SharePoint designer workflow
set Item Value activity can do this work, you can research to find more information about how to do this.
Thanks,
Qiao Wei <br/> My blog:http://blog.goobol.com -
Issues while joining two tables as the joining column has duplicate values - Please help!
Hi,
I have a table A -which has few columns including a Amount column - I am joining this table A to Table B. The joining column in B has duplicates. So, the number of records are getting more after the joining. As per the requirment when I create a table
after joining the tables and count the salary clumn, there is a difference in the counting. How can I solve this? Can you please help me?
Here is the DDL and sample values
create table #student (sid int, name varchar(10),salary int)
create table [#address] (sid int, city varchar(10),grade char(1),lineneumber int)
insert into #student values (1,'sachin',8000)
insert into #student values (2,'Dhoni',2000)
insert into #student values (3,'Ganguly',7000)
insert into #student values (4,'Kohli',1000)
insert into [#address] values(1,'mumbai','A',1)
insert into [#address] values(1,'mumbai','B',2)
insert into [#address] values(1,'mumbai','C',3)
insert into [#address] values(1,'mumbai','D',4)
insert into [#address] values(2,'JARKHAND','D',3)
insert into [#address] values(2,'JARKHAND','D',4)
SELECT S.SID,NAME,salary,CITY ,grade,linenumber
into #FINAL
FROM #STUDENT S
LEFT JOIN #ADDRESS A
ON S.SID=A.SID
SELECT SUM(salary) FROM #FINAL
--44000
Final result should be 18000 , but it is coming as 44000. can you please help me to get the correct result - what do i do in the joining?
In my real project, i have 5 tables joining, each table have more than 30 columns and few joining tables joining column have duplicates. I have simplified the issue so that i can ask the question clearly. So,while answering, please consider that also in mind.
thanks in advance for your help!SELECT S.SID,NAME,salary,CITY
into #FINAL
FROM #STUDENT S
LEFT JOIN (SELECT DISTINCT sid,city
FROM #Address) A
ON S.SID=A.SIDthis will do a join on student table and city table with unique sid and city name so adddress selection will be sid city1 mumbai2 jarkand -
Import flat file to multiple tables based on identifier column
Hello,
I am trying to setup a package that will import one pipe-delimited flat file (a utility bill) to multiple data tables based on the value of the first column. I have been told it is similar in format to an EDI file, but there are some differences.
The number of columns is consistent where the first columns are the same. Meaning a record that has '00' in the first column will always have 10 columns; a record that has '01' in the first column will always have 9 columns; etc.
Each value in the first column represents a separate destination data table. Meaning a record that has '00' in the first column should be output to table '00'; a record that has '01' in the first column should be output to table '01'; etc. All
destination tables reside on the same SQL Server.
Identifier columns can repeat multiple times throughout the flat file. Meaning a record that starts with '01' may be repeated multiple times in the same.
Sample Data:
00|XXXXXXXX|XXX|XXXXXXXX|XXXXXX|XXXX|X|XXXXXXXXXX|XX|XXXXX
01|XXXXXXXXXXX|XXX|XXXXXXXX|XXXXX|XXXXXXXXXXXXXXXXXXXX|XXXXXXXXXX|XXXXXXX|XXXXXXXXXXXXXX
02|XXXXXXXXXXX|XXXXXXXX|XXXXXXX|XXXXX|XXXXX|XXXXX|XXXXX|XXXXX|XXXXX|XXXXX|XXXXX
04|XXXXXXXXXXX|XXXXXXXXXXXXX|XXX|XXXXXXXX
05|XXXXXXXXXXX|XXXXXXXXXXXXX|XXX|XXXXXXXX|XXXX
07|XXXXXXXXXXXXX|X|XXXXXXXXXXXXXXX|XXX|XXXXXXXX|XXXX|XXXXXXX|XXXXXXXXXXX
07|XXXXXXXXXXXXX|X|XXXXXXXXXXXXXXX|XXX|XXXXXXXX|XXXX|XXXXXXX|XXXXXXXXXXX
07|XXXXXXXXXXXXX|X|XXXXXXXXXXXXXXX|XXX|XXXXXXXX|XXXX|XXXXXXX|XXXXXXXXXXX
07|XXXXXXXXXXXXX|X|XXXXXXXXXXXXXXX|XXX|XXXXXXXX|XXXX|XXXXXXX|XXXXXXXXXXX
01|XXXXXXXXXXX|XXX|XXXXXXXX|XXXXX|XXXXXXXXXXXXXXXXXXXX|XXXXXXXXXX|XXXXXXX|XXXXXXXXXXXXXX
02|XXXXXXXXXXX|XXXXXXXX|XXXXXXX|XXXXX|XXXXX|XXXXX|XXXXX|XXXXX|XXXXX|XXXXX|XXXXX
04|XXXXXXXXXXX|XXXXXXXXXXXXX|XXX|XXXXXXXX
Any help would be appreciated.Hi koldar.308,
If there are few distinct values in the first column, we can use Flat File Source connect to that flat file, then use Conditional Split Transformation to split the first column to multiples, and then load the data to multiple tables with OLE DB Destination
based on the outputs of Conditional Split.
After testing the issue in my environment, please refer to the following steps to achieve this requirement:
Drag a Flat File Source connect to that flat file with Flat File Connection Manager.
Drag a Conditional Split Transformation connects to the Flat File Source.
Double-click the Conditional Split Transformation, add several Output based on the first column values as below:
Drag same number OLE DB Destinations as the outputs of Conditional Split, connect to Conditional Split with one case output:
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
If you have any feedback on our support, please click
here.
Katherine Xiong
TechNet Community Support
Maybe you are looking for
-
HT1688 How to use iMessage with only one apple account.
I updated my iphone4 and my husbands iphone3s and my ipad2 to iOS6. I have one apple account for all of them....well now my email, which is my login, is hooked to all 3 for imessage. So if I send my husband a imessage it sends it to all 3 of them....
-
The home button on my iPod Touch 4G is barely working!
I have to press my home button and my sleep button about 10 times to get it to respond, does anyone have any idea why both buttons would act up? My ipod is nearly full, as in MBs away from it, would that have anything to do with the slow movement??
-
ICloud photos restore not working :(
I restored my 3GS to iOS5.1 and restored from iCloud, but when I go into photos, it's stuck on Downloading 57 of 492 I have restored from iCloud before and it worked fine, why is it stuck this time?! Somebody please help me soon!
-
Hi I tried to search forum for this but did not get satisfactory answer. I'm trying to understand Co09(Availibility check) screen. there are 3 columns rec./reqd qty, confirmed and ***. ATP qty. Please explain how read it.
-
Regarding bacground sheduling for materials
After running a BDC program in background for materials, next day morning when you see the results, few records are not updated(error records). What will you do then?