Combine two tables T-SQL
Hi there,
It might be simple Query for you but I was missing the logic.
I have Tab A this does have 4 records.
Tab B this does have 14 records.
Note: those 4 records exists in Tab B
I want to insert rest of the 10 records into the Tab A.
Any suggestion pls.
Thanks,
Siva
Hi,
Please run the below script and see if it serves your requirement.
DECLARE @TableA TABLE
ID INT,
NAME VARCHAR(10)
INSERT INTO @TableA
VALUES (1, 'James')
,(2, 'Ramz')
,(3, 'Chandu')
,(4, 'Suraj')
SELECT *
FROM @TableA
DECLARE @TableB TABLE
ID INT,
NAME VARCHAR(10)
INSERT INTO @TableB
VALUES (1, 'James')
,(2, 'Ramz')
,(3, 'Chandu')
,(4, 'Suraj')
,(5, 'Krishna')
,(6, 'John')
SELECT *
FROM @TableB
Now as per your requirement, you need to insert rows 5 & 6 from TableB into TableA
INSERT INTO @TableA
SELECT Tab1.*
FROM @TableB Tab1
LEFT JOIN @TableA Tab2 ON Tab1.id = Tab2.id
WHERE Tab2.id IS NULL
The above query gives inserts the non-existing records
SELECT *
FROM @TableA
Thanks, Satish Chandra
Similar Messages
-
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 -
Combining two tables into one result
Hi all, I am fairly inexperienced with Crystal but have gained good results from the reports I have created, I am fluent in SQL and Basic to an extent. I am interigating a Pronto database and I want concatenate two tables into one report.
Table One: Customer Orders
Fields: Customer No, Invoice Number, Invoice date, Invoice Amount, Cost Amount.
Table Two: Archived Customer Orders
Fields: Customer No, Invoice Number, Invoice date, Invoice Amount, Cost Amount.
I want to complete a report that will tell me the sales for a given period and the outstanding orders for each customer total for all fields in each table combined into one figure.
Any help would be greatly appreciated.
Thanks in advanceHi Grant,
As you said you are goot at writing SQL, in Crystal write a SQL statement in Add Command to join both table using Union / Union all
If you use Union then it will filter duplicate records and pull the data from database, If you use Union All then it will include all your duplicate records. Please use Union / Union All as required.
Once you get all data into the report create a parameter for date range and generate the summaries as required.
Thanks,
Sastry -
Hello Guys,
Is it possible to create this kinda output.
Input:
Table1
Column1
Column
1
A
2
B
3
C
4
D
Table2
A
B
C
D
0
1
0
0
1
0
1
0
0
1
1
1
0
1
0
1
Output:
B
AC
BCD
BD
Actually i want to Combine two different table column deepen where 1 .
thanksHello ,
you need to use PIVOT ,See the below sample :
Step 1 :
insert into DailyIncome values ('SPIKE', 'FRI', 100)
insert into DailyIncome values ('SPIKE', 'MON', 300)
insert into DailyIncome values ('FREDS', 'SUN', 400)
insert into DailyIncome values ('SPIKE', 'WED', 500)
insert into DailyIncome values ('SPIKE', 'TUE', 200)
insert into DailyIncome values ('JOHNS', 'WED', 900)
insert into DailyIncome values ('SPIKE', 'FRI', 100)
insert into DailyIncome values ('JOHNS', 'MON', 300)
insert into DailyIncome values ('SPIKE', 'SUN', 400)
insert into DailyIncome values ('JOHNS', 'FRI', 300)
insert into DailyIncome values ('FREDS', 'TUE', 500)
insert into DailyIncome values ('FREDS', 'TUE', 200)
insert into DailyIncome values ('SPIKE', 'MON', 900)
insert into DailyIncome values ('FREDS', 'FRI', 900)
insert into DailyIncome values ('FREDS', 'MON', 500)
insert into DailyIncome values ('JOHNS', 'SUN', 600)
insert into DailyIncome values ('SPIKE', 'FRI', 300)
insert into DailyIncome values ('SPIKE', 'WED', 500)
insert into DailyIncome values ('SPIKE', 'FRI', 300)
insert into DailyIncome values ('JOHNS', 'THU', 800)
insert into DailyIncome values ('JOHNS', 'SAT', 800)
insert into DailyIncome values ('SPIKE', 'TUE', 100)
insert into DailyIncome values ('SPIKE', 'THU', 300)
insert into DailyIncome values ('FREDS', 'WED', 500)
insert into DailyIncome values ('SPIKE', 'SAT', 100)
insert into DailyIncome values ('FREDS', 'SAT', 500)
insert into DailyIncome values ('FREDS', 'THU', 800)
insert into DailyIncome values ('JOHNS', 'TUE', 600)
Now :
VendorId IncomeDay IncomeAmount
SPIKE FRI 100
SPIKE MON 300
FREDS SUN 400
SPIKE WED 500
SPIKE TUE 200
JOHNS WED 900
SPIKE FRI 100
JOHNS MON 300
SPIKE SUN 400
SPIKE WED 500
FREDS THU 800
JOHNS TUE 600
Step 3:
select * from DailyIncome
pivot (avg (IncomeAmount) for IncomeDay in ([MON],[TUE],[WED],[THU],[FRI],[SAT],[SUN])) as AvgIncomePerDay
Output :
VendorId MON TUE WED THU FRI SAT SUN
FREDS 500 350 500 800 900 500 400
JOHNS 300 600 900 800 300 800 600
SPIKE 600 150 500 300 200 100 400
More details
Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/ -
Combine two tables without common field
Hi Experts,
I have two database tables, DBSTATORA(stores inform about all the tables involved in infoproviders), and RSDODSO ( stores information about ODS Objects. I have to list the ods objects and its associated tables as the output, but there is no common field in these two tables how will i combine these two tables, can anyone please suggest me. Any help will be fine.
thanks,
Prabhu.Hi Everyone,
I know the ods tables names are stored like /bix/a<ods_name>00 and /bix/a<ods_name>40 and for change log it is /bic/b*. But my requirement is I have to display the size of the tables belonging to a particular ods object. So for all the tables the size is stored in DBSTATTORA which gives information about
DBSTATTORA
fields of this tables are:
TNAME --> Table Name
ANDAT --> Analyzing Date
AMETH --> Analysis method for collecting Statistics
NROWS --> No of rows in a table
OCCBL --> Used blk(size) of table in KB
EMPBL --> Empty blk(size) of table in KB
AFREE --> Avg Freespace in a used db block
INDBS --> Used Blk(size) of an index kb
This is a table which stores the statistics information.
It displays all the tables of infocubes and ods objects, but does tell that this table belongs to this infoprovider.
I have to display data from this table as well as the infoprovider to which it belongs. So there is no proper information of database tables where the infocube and its associated tables like the facttable, dimtables are stored together. Same for the ods objects also.
There are for ods object RSDODSOTABL which give information about ods object and the table name is stored differently <ods_name>_0000. How do i map this table with the DBSTATTORA table, the tablenames doesn't match. Same problem with RSTSODS table which give informaiton about change log table.
And also for infocubes, there is RSDCUBE which gives information about infocubes but not the associated tables. So does anyone know where all these information is stored in some database tables. It would be of great help.
Thanks a lot.
Prab -
Question about combining two tables
I have two tables that I want to combine them together:
Table A: ID x
49 3
127 1
Table B: ID y
49 1
83 2
127 1
Expected combined table C: ID x y
49 3 1
83 0 2
127 1 1
Seems I have to do two out join and them union them together. Any better ways?
Thanks
garyThe tables are not displayed properly. try it again:Use the {noformat}{noformat} tag for that.
Put it before and after your example.
So, when you type or paste your formatted code like this:
{noformat}select *
from dual;{noformat}
it will appear as:select *
from dual;on this forum -
I have the following two tables:
Asset_Issued
Asset_Type_ID
Assigned To
1
Ram
2
Ram
3
Ram
4
Ram
5
Ram
1
Raju
3
Raju
5
Raju
1
Rajesh
3
Rajesh
2
Rajesh
Asset_Type
Asset_Type_ID
Asset_Name
1
Laptop
2
Desktop
3
Mouse
4
Keyboard
5
Monitor
Can anyone help me with the query that will give the following result.
Asset_Issued_Count
Asset_Name
Count
Laptop
3
Desktop
2
Mouse
3
Keyboard
1
Monitor
1I think your OUTPUT COUNT for MONITOR should be 2 and not 1. Try the below.
WITH ASSET_ISSED(ASSET_TYPE_ID,ASSIGNED_TO) AS(
SELECT 1,'Ram' FROM DUAL UNION ALL
SELECT 2,'Ram' FROM DUAL UNION ALL
SELECT 3,'Ram' FROM DUAL UNION ALL
SELECT 4,'Ram' FROM DUAL UNION ALL
SELECT 5,'Ram' FROM DUAL UNION ALL
SELECT 1,'Raju' FROM DUAL UNION ALL
SELECT 3,'Raju' FROM DUAL UNION ALL
SELECT 5,'Raju' FROM DUAL UNION ALL
SELECT 1,'Rajesh' FROM DUAL UNION ALL
SELECT 3,'Rajesh' FROM DUAL UNION ALL
SELECT 2,'Rajesh' FROM DUAL),
ASSET_TYPE(ASSET_TYPE_ID,ASSET_NAME) AS
(SELECT 1,'Laptop' FROM DUAL UNION ALL
SELECT 2,'Desktop' FROM DUAL UNION ALL
SELECT 3,'Mouse' FROM DUAL UNION ALL
SELECT 4,'Keyboard' FROM DUAL UNION ALL
SELECT 5,'Monitor' FROM DUAL)
SELECT ASSET_NAME,
COUNT(1)
FROM
ASSET_ISSED T1,
ASSET_TYPE T2
WHERE T1.ASSET_TYPE_ID=T2.ASSET_TYPE_ID
GROUP BY T2.ASSET_NAME;
OUTPUT:
ASSET_NA COUNT(1)
Desktop 2
Laptop 3
Mouse 3
Keyboard 1
Monitor 2 -
Hi,
Iam struggling with SQL for this scenario..can you please through some light on this.
Table A:
Order Number || W.O.Number || Enetrprise || ResourcePool
1 || 1 || A || RP1
2 || 2 || A || RP1
3 || 3 || A || RP2
4 || 4 || A || RP2
5 || 5 || A || RP3
B
ResourcePool || Available Date
RP1 || 20-Dec-2007
RP1 || 21-Dec-2007
RP1 || 22-Dec-2007
RP2 || 20-Dec-2007
RP2 || 21-Dec-2007
RP3 || 20-Dec-2007
RP3 || 21-Dec-2007
My query should fetch
Order Number|| W.O.Number|| Enetrprise|| ResourcePool|| Available Date
1 || 1 || A || RP1 || 20-Dec-2007
1 || 1 || A || RP1 || 21-Dec-2007
1 || 1 || A || RP1 || 22-Dec-2007
2 || 2 || A || RP1 || 20-Dec-2007
2 || 2 || A || RP1 || 21-Dec-2007
2 || 2 || A || RP1 || 22-Dec-2007
3 || 3 || A || RP2 || 20-Dec-2007
3 || 3 || A || RP2 || 21-Dec-2007
4 || 4 || A || RP2 || 20-Dec-2007
4 || 4 || A || RP2 || 21-Dec-2007
5 || 5 || A || RP2 || 20-Dec-2007
5 || 5 || A || RP2 || 21-Dec-2007
when Iam including A.resourcepool=B.resourcepool in the query its returning no rows.
Thanks(repeated)
select Order Number,W.O.Number, Enetrprise, a.ResourcePool, Available Date
from a,b
where a.resourcepool=b.resourcepool;
this is the simplest join condition.
just check whether you have some data in those tables! -
SELECT providerid, SUM(COUNT) FROM appdev.usercounts
WHERE counttime BETWEEN SYSDATE - 30/1440 AND SYSDATE- 15/1440 GROUP BY providerid ORDER BY providerid
W 697
U 813
T 143
S 2
SELECT providerid, SUM(COUNT) FROM appdev.usercounts
WHERE counttime BETWEEN (SYSDATE -1) - 30/1440 AND (SYSDATE-1)- 15/1440 GROUP BY providerid ORDER BY providerid;
W 450
U 571
T 80
S 2
I wnat output as like
W 697 450
U 813 571
T 143 80
S 2 2
please help
Thanks
Praveen"COUNT", is that the real column name? It could become very confusing.
Not tested for obvious reasons, but this should be close :
SELECT providerid
, sum(
case when counttime between sysdate - 30/1440 and sysdate - 15/1440 then count end
) as cnt1
, sum(
case when counttime between (sysdate-1) - 30/1440 and (sysdate-1) - 15/1440 then count end
) as cnt2
FROM appdev.usercounts
WHERE ( counttime between sysdate - 30/1440 and sysdate - 15/1440 )
OR ( counttime between (sysdate-1) - 30/1440 and (sysdate-1) - 15/1440 )
GROUP BY providerid
ORDER BY providerid
; -
How to combine two datatable in c#}
Hi Everybody,
I have two datatables I want to combine single output.
First datatable1 result
A1 A2
10 15
Second datatable2 result
B1 B2
5 10
The final result should be in datatable3
A1 A2 B1 B2
10 15 5 10Hi,
SQL Server do not have datatables but tables. Datatables
(datatable)
is a dot.Net object. You can read more about DataTable class here: http://msdn.microsoft.com/en-us/library/system.data.datatable(v=vs.110).aspx
Are you talking about DataTable or tables in database?
>> Combining two DataTables objects in dot.net can be done with the DataTable.Merge Method.
>> combining two tables in SQL Server database can be done using the Merge operation in T-SQL (as other mentioned before me)
[Personal Site] [Blog] [Facebook] -
How to combine two datarows (business component data) in BI Publisher
Hi ,
We are using BI Publisher in Siebel Environment.
We have data coming from two business components (like from 2 diff tables)
a) <?for-each:ssTest1?>
b) <?for-each:ssTest2?>
ssTest1 and ssTest2 are the business components
We need to combine these 2 datarows (a&b) and show the data into a single combined data row for ex like <?for-each:ssTest1ssTest2?> and show all the fields in that.
I'm not sure how we can combine these two data rows into a single combined data row and show the data.
Any help from any one would be apprecated.
Thanks
PV
Edited by: user8633002 on Oct 21, 2010 4:05 PMHi sajid
There was nothing more description about your issue in this site and I found an issue below is mostly like yours
http://www.codeproject.com/Questions/855487/how-to-combine-two-table-value-in-rdlc-report
In the issue above, if you want to show the two other tables in the report, I think you could combine the tables into one datatable joining on key. The link below show an example of a DataSet Helper from Microsoft about combine DataSets. Take note of
the related content for other DataSet Helper examples. And then you could use the datatable in your RDLC.
# HOW TO: Implement a DataSet JOIN helper class in Visual C# .NET
http://support.microsoft.com/kb/326080/en-us
In an alternative way, I think you could create a view in the database which combine your tables and use it in your rdlc.
In addition, your issue is about asp.net and you could get more support in the asp.net forum whose link as below.
http://forums.asp.net
Best Regards
Edward
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a
href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey. -
How to specify more than Two Tables in NATURAL JOIN
Hi,
I am using Oracle9i R-2. I want help in writing a Query using Two Tables in SQL*PLUS. I am using ANSI/ISO Standrard for table-joins:
select col1, col2, descr
from tab1 natural join tab2
There are two columns col1 & col2 is common between thse two tables. So, it will join them and query execute well.
How can i use 3rd table tab3 in the same way in Natural Join...? If column col1 & col2 is available in tab3 also.
I tried this way, but it gives me error:
select col1, col2
from tab1 natural join tab2 natural join tab3
Is it possible to specify more than two tables in Natural Join Clause.
Please check that out & help please. Thanks.
Regards,
Kamesh RastogiI do not get an error when I try the same thing on the same version, as demonstrated below. Can you post your table structure and a copy and paste of a run of your actual query with the error that you are receiving?
scott@ORA92> select banner from v$version
2 /
BANNER
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
CORE 9.2.0.1.0 Production
TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
NLSRTL Version 9.2.0.1.0 - Production
scott@ORA92> select * from tab1
2 /
COL1 COL2 COL3
1 1 A
10 10 B
scott@ORA92> select * from tab2
2 /
COL1 COL2 COL4
1 1 C
20 20 D
scott@ORA92> select * from tab3
2 /
COL1 COL2 COL5
1 1 E
30 30 F
scott@ORA92> select col1, col2, col3, col4, col5
2 from tab1 natural join tab2 natural join tab3
3 /
COL1 COL2 COL3 COL4 COL5
1 1 A C E
scott@ORA92> -
Combinig two tables without a JOINER
Hi,
I got a little problem. I want to combine two tables. But I don't need a joiner, cause that would give me wrong combined values.
I have a table working_hours which has the actual working hours of employees. And a table times_absent which has the absent time of the employees.
Both tables have the date and actual hours of work and absent besides other tings in it.
I simple want to combine these two tables to one big table.
Example:
Table working_hours :
Name --- Date --- Hours -- ....
Mr.A --- 2.5.2011 --- 8 --- ...
Mr.B --- 2.5.2011 --- 6 --- ...
Mr.C --- 2.5.2011 --- 7 --- ...
Table times_absent:
Name --- Date --- Days --- ....
Mr.A --- 3.5.2011 --- 1 --- ...
Mr.B --- 3.5.2011 --- 2 --- ...
Mr.B --- 4.5.2011 --- 2 --- ...
New Table:
Name --- Date --- Working_Hours --- Absent_Days ---
Mr.A --- 2.5.2011 --- 8 ---- null - or some sort of dummy value XXX
Mr.A --- 3.5.2011 --- null --- 1 ---
Mr.B --- 2.5.2011 --- 6 --- null ---
Mr.B --- 3.5.2011 --- null --- 2 ---
Mr.B --- 4.5.2011 --- null --- 2 ---
and so one.
Is there a possibility in the OWB to perform such task?
thxAs MccM says you need to make the columns in your IN groups the same i.e. the same structure as your new table.
Connect WORKING HOURS to IN GROUP 1 and ABSENT to IN GROUP 2 for the columns that exist.
Create a numeric CONSTANT with a default value of NULL and connect that to ABSENT_DAYS in IN GROUP 1 and WORKING_HOURS in IN GROUP 2.
You don't need to change the structure of your tables. -
Possible to combine two xml documents into a single query?
In ASP, PHP, etc. if I wanted to combine two tables and
filter by one =
item, I would create a recordset combining the two on one
common element =
and have one recordset. Is that possible with xml documents
and Spry =
datasets?
I have xml information sent to me 4 times a day from a
weather service. =
This happens automatically, but the two xml documents
(current.xml and =
forecast.xml) are set in stone by the service. However, if in
my Spry =
dataset, I could combine them so I could list the 15 cities
in a master =
region and have tabs for the current conditions and forecast
which would =
each access a separate xml document but needs to do that from
the city =
link on the left, that would work great.
Can I do this as I would be able to if I had a database with
different =
tables?
Thanks!
NancyHi Kin:
They are really static xml files that are placed in a folder
directly by =
the weather service. The files in question are current.xml
and =
forecast.xml.
And there is not one per city .. but just one of each. the
location =
node in current.xml and the citycode node in forecast.xml
contain the =
same information.
If I were doing this in a recordset with a database, I would
write =
something like SELECT whatever from current, forecast WHERE =
current.location =3D forecast.citycode AND current.location
=3D variable =
(which would be what is clicked on).
This sets up a master/detail arrangement for the first one
that works =
fine. Click on the city code (which I have to write something
to say If =
location =3D FAT, document.write "Fresno" and so on) and the
rest of the =
current information displays fine on the right side of the
page. Now I =
have to marry that to the forecast.xml file so that when
citycode =3D =
FAT, the five day information for Fresno shows up .. and so
on. I was =
planning to use Spry tabs or whatever to show the data.
<!--
var dsCurrent =3D new Spry.Data.XMLDataSet("current.xml", =
"weather/current");
//-->
</script>
</head>
<body>=20
<div class=3D"MasterDetail">
<div spry:region=3D"dsCurrent"
class=3D"MasterContainer">
<div class=3D"MasterColumn" spry:repeat=3D"dsCurrent" =
spry:setrow=3D"dsCurrent" spry:hover=3D"MasterColumnHover" =
spry:select=3D"MasterColumnSelected">{location}</div>
</div>
<div spry:detailregion=3D"dsCurrent"
class=3D"DetailContainer">
<div class=3D"DetailColumn">{phrase}</div>
<div class=3D"DetailColumn">{temp}</div>
<div class=3D"DetailColumn">{temp/@units}</div>
<div class=3D"DetailColumn">{aptemp}</div>
<div class=3D"DetailColumn">{aptemp/@unit}</div>
<div class=3D"DetailColumn">{wndchl}</div>
<div class=3D"DetailColumn">{wndchl/@unit}</div>
<div class=3D"DetailColumn">{rhumid}</div>
<div class=3D"DetailColumn">{rhumid/@unit}</div>
<div class=3D"DetailColumn">{wind_dir}</div>
<div class=3D"DetailColumn">{windspeed}</div>
<div
class=3D"DetailColumn">{windspeed/@unit}</div>
<div class=3D"DetailColumn">{pres}</div>
<div class=3D"DetailColumn">{pres/@unit}</div>
<div class=3D"DetailColumn">{vis}</div>
<div class=3D"DetailColumn">{vis/@unit}</div>
<div class=3D"DetailColumn">{icon}</div>
</div>
Arnout gave me some suggestions .. but so far, I haven't
gotten either =
of them to work. Also I am trying to get some ideas from spry
Samples =
from the Spry home page/samples area, but again .. not yet.
Thanks,
Nancy
"kinblas" <[email protected]> wrote in
message =
news:[email protected]...
>I don't think you need to combine them just so they can
render in a =
tabbed=20
> widget. We're still missing a couple of key pieces of
information. =
What does=20
> the data that is used in the master region look like?
Are what you =
refer to as=20
> current.xml and forecast.xml really static files? Or are
they =
dynamically=20
> generated by a server side script (php/cf/etc)? There is
one current =
and=20
> forecast xml per city right?
>=20
> I ask these questions because you may be able to simply
set up a =
master detail=20
> relationship between 3 data sets and just use those
within a region(s) =
that=20
> build up the tab widget. Assuming you were getting the
list of cities =
from a=20
> 3rd source, you could set up something like this:
>=20
>=20
> var dsCities =3D new Spry.Data.XMLDataSet("cities.xml",
=
"/cities/city");
> var dsCurrent =3D new=20
>
Spry.Data.XMLDataSet("current.php?location=3D{dsCities::name}",=20
> "/weather/current");
> var dsForecast =3D new=20
>
Spry.Data.XMLDataSet("forecast.php?citycode=3D{dsCities::name}",=20
> "/weather/forecast/day");
>=20
>=20
> ...
>=20
>=20
> <div id=3D"TabbedPanels1" class=3D"TabbedPanels">
> <ul class=3D"TabbedPanelsTabGroup">
>
Current</li>
>
Forecast</li>
>
> <div class=3D"TabbedPanelsContentGroup">
> <div class=3D"TabbedPanelsContent"
spry:region=3D"dsCurrent">
> {temp}{temp/@unit}
> </div>
> <div class=3D"TabbedPanelsContent"
spry:region=3D"dsForecast">
>
> <li spry:repeat=3D"dsForecast">{name}<br
/>High: =
{high}{high/@unit}<br=20
> />Low: {low}{low/@unit}</li>
>
> </div>
> </div>
> </div>
>=20
>=20
>=20
> --=3D=3D Kin =3D=3D--
> -
Loading two tables at same time with SQL Loader
I have two tables I would like to populate from a file C:\my_data_file.txt.
Many of the columns I am loading into both tables but there are a handful of columns I do not want. The first column I do not want for either table. My problem is how I can direct SQL Loader to go back to the first column and skip over it. I had tried using POSITION(1) and FILLER for the first column while loading the second table but I got THE following error message:
SQL*Loader-350: Syntax error at line 65
Expecting "," or ")" found keyword Filler
col_a Poistion(1) FILLER INTEGER EXTERNALMy control file looks like the following:
LOAD DATA
INFILE 'C:\my_data_file.txt'
BADFILE 'C:\my_data_file.txt'
DISCARDFILE 'C:\my_data_file.txt'
TRUNCATE INTO TABLE table_one
WHEN (specific conditions)
FIELDS TERMINATED BY ' '
TRAILING NULLCOLS
col_a FILLER INTEGER EXTERNAL,
col_b INTEGER EXTERNAL,
col_g FILLER CHAR,
col_h CHAR,
col_date DATE "yyyy-mm-dd"
INTO TABLE table_two
WHEN (specific conditions)
FIELDS TERMINATED BY ' '
TRAILING NULLCOLS
col_a POSITION(1) FILLER INTEGER EXTERNAL,
col_b INTEGER EXTERNAL,
col_g FILLER CHAR,
col_h CHAR,
col_date DATE "yyyy-mm-dd"
)Try adapting this for your scenario.
tables for the test
create table test1 ( fld1 varchar2(20), fld2 integer, fld3 varchar2(20) );
create table test2 ( fld1 varchar2(20), fld2 integer, fld3 varchar2(20) );
control file
LOAD DATA
INFILE "test.txt"
INTO TABLE user.test1 TRUNCATE
WHEN RECID = '1'
FIELDS TERMINATED BY ' '
recid filler integer external,
fld1 char,
fld2 integer external,
fld3 char
INTO TABLE user.test2 TRUNCATE
WHEN RECID <> '1'
FIELDS TERMINATED BY ' '
recid filler position(1) integer external,
fld1 char,
fld2 integer external,
fld3 char
data for loading [text.txt]
1 AAAAA 11111 IIIII
2 BBBBB 22222 JJJJJ
1 CCCCC 33333 KKKKK
2 DDDDD 44444 LLLLL
1 EEEEE 55555 MMMMM
2 FFFFF 66666 NNNNN
1 GGGGG 77777 OOOOO
2 HHHHH 88888 PPPPP
HTH
RK
Maybe you are looking for
-
Why is my iPhone 5S not getting any coverage?
I go to a high school that has some sort of signal blocker so students can't call and text while in class, although there is Wi-Fi available. So, I turn on Airplane Mode and turn on Wi-Fi and I connect to the school Wi-Fi. When I leave school, I turn
-
Reading big JTable from disk one page at a time
Hi, I'm trying to display a JTable in its JScrollPane for a large amount of data (say 40'000 records). Scrolling is quite smart, since it does a relatively good job when the user drags the knob, e.g. in order to reach the bottom. However, it leaves s
-
BW Error : TSV_TNEW_PAGE_ALLOC_FAILED
Hi All, While updating data from PSA of an infopackage i got a short dump called TSV_TNEW_PAGE_ALLOC_FAILED. So,I made the status of infopackage red and deleted the request. Will the data be there in the PSA? If yes,then how to upload the data from
-
I am updating my site to a new custom theme. The old site was light text on dark background. The new site is dark text on light background. Is there a way to update the theme of a photo sharing block/slideshow so that the text in the photo block (is
-
Need of Initial level document
Hi Experts! I am new to SAP XI. Can I get the URL or document from where i can learn step by step activities to configure PI . It will be helpful for me to learn PI. Regards, Rekha.K