dbTalk Databases Forums  

Fetching Data from 2 tables and send in text File using query

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Fetching Data from 2 tables and send in text File using query in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
chintu4uin@gmail.com
 
Posts: n/a

Default Fetching Data from 2 tables and send in text File using query - 12-08-2009 , 12:50 AM






Hi friends need help for the following
I m using SQL 2000
What I want to do is I want to create a single Text File containg
data from 2 tables using DTS.
Basically my First Table is having 10 columns and second table is
having 40 columns so my text file will be generating of 50 columns in
that what I want to do is If suppose my first table has 5 rows and
second table has 20 rows so final text file will be having 25 rows in
all.
Now in text file first five rows should be of Table A which has 10
columns so from 11th column ownward it will have all null data.From
6th row ownward my second table is having data so in that case 1-10
columns will have null data and from 11th coulmn Table B data will be
there now I want to form a query in such a way that my result set
should be as mention above.

Sample
Table A
-------------------
Col A1 | Col A2 | Col A3
1 XYZ 10
2 MNO 20

Table B
-------------------
Col B1 | Col B2 | Col B3 | Col B4
1 x m 10
2 y n 20

Query Resultset
-------------------
Col A1 | Col A2 | Col A3 | Col B1 | Col B2 | Col B3 | Col B4
1 XYZ 10 null null null
null
2 MNO 20 null null null
null
null null null 1 x
m 10
null null null 2 y
n 20

So I will send this query in DTS to generate a Text file as shown in
resultset.
Please friend any one can suggest something..
Irrespective of relation I want to fetch data from both table and form
File so what can be the query to do so.

Reply With Quote
  #2  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Fetching Data from 2 tables and send in text File using query - 12-08-2009 , 01:48 AM






On Mon, 7 Dec 2009 22:50:40 -0800 (PST), chintu4uin (AT) gmail (DOT) com wrote:

Quote:
Hi friends need help for the following
I m using SQL 2000
What I want to do is I want to create a single Text File containg
data from 2 tables using DTS.
Basically my First Table is having 10 columns and second table is
having 40 columns so my text file will be generating of 50 columns in
that what I want to do is If suppose my first table has 5 rows and
second table has 20 rows so final text file will be having 25 rows in
all.
Now in text file first five rows should be of Table A which has 10
columns so from 11th column ownward it will have all null data.From
6th row ownward my second table is having data so in that case 1-10
columns will have null data and from 11th coulmn Table B data will be
there now I want to form a query in such a way that my result set
should be as mention above.

Sample
Table A
-------------------
Col A1 | Col A2 | Col A3
1 XYZ 10
2 MNO 20

Table B
-------------------
Col B1 | Col B2 | Col B3 | Col B4
1 x m 10
2 y n 20

Query Resultset
-------------------
Col A1 | Col A2 | Col A3 | Col B1 | Col B2 | Col B3 | Col B4
1 XYZ 10 null null null
null
2 MNO 20 null null null
null
null null null 1 x
m 10
null null null 2 y
n 20

So I will send this query in DTS to generate a Text file as shown in
resultset.
Please friend any one can suggest something..
Irrespective of relation I want to fetch data from both table and form
File so what can be the query to do so.
Hi chintu4uin,

The query to get this result set is as follows:

SELECT ColA1, ColA2, ColA3,
NULL AS ColB1, NULL AS ColB2, NULL AS ColB3
FROM TableA
UNION ALL
SELECT NULL AS ColA1, NULL AS ColA2, NULL AS ColA3,
ColB1, ColB2, ColB3
FROM TableB;

How to embed this in DTS is beyond me, for I never used DTS. But I
assume you can just call this query from DTS and get the results.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

Reply With Quote
  #3  
Old   
BrianR
 
Posts: n/a

Default Re: Fetching Data from 2 tables and send in text File using query - 12-08-2009 , 09:49 AM



To add dts package, in enterprise manager

Reply With Quote
  #4  
Old   
chintu4uin@gmail.com
 
Posts: n/a

Default Re: Fetching Data from 2 tables and send in text File using query - 12-14-2009 , 02:46 AM



On Dec 8, 12:48*pm, Hugo Kornelis
<h... (AT) perFact (DOT) REMOVETHIS.info.INVALID> wrote:
Quote:
On Mon, 7 Dec 2009 22:50:40 -0800 (PST), chintu4... (AT) gmail (DOT) com wrote:
Hi friends need help for the following
I m using SQL 2000
What I want to do is I want to create a single Text File *containg
data from 2 tables using DTS.
Basically my First Table is having 10 columns and second table is
having 40 columns so my text file will be generating of 50 columns in
that what I want to do is If suppose my first table has 5 rows and
second table has 20 rows so final text file will be having 25 rows in
all.
Now in text file first five rows should be of Table A which has 10
columns so from 11th column ownward it will have all null data.From
6th row ownward my second table is having data so in that case 1-10
columns will have null data and from 11th coulmn Table B data will be
there now I want to form a query in such a way that my result set
should be as mention above.

Sample
Table A
-------------------
Col A1 | Col A2 | Col A3
* *1 * * * * XYZ * * *10
* *2 * * * * MNO * * *20

Table B
-------------------
Col B1 | Col B2 | Col B3 | Col B4
* 1 * * * * * x * * * * * *m * * * * 10
* 2 * * * * * y * * * * * *n * * * * 20

Query Resultset
-------------------
Col A1 | Col A2 | Col A3 | Col B1 | Col B2 | Col B3 | Col B4
* *1 * * * * XYZ * * *10 * * * * null * ** * *null * * * null
null
* *2 * * * * MNO * * 20 * * * * null * * * * *null * * * null
null
* *null * * * * null * * null * * * * 1 * ** * * x
m * * * * 10
* *null * * * * null * * null * * * * *2 * * * * * y
n * * * * 20

So I will send this query in DTS to generate a Text file as shown in
resultset.
Please friend any one can suggest something..
Irrespective of relation I want to fetch data from both table and form
File so what can be the query to do so.

Hi chintu4uin,

The query to get this result set is as follows:

SELECT ColA1, ColA2, ColA3,
* * * *NULL AS ColB1, NULL AS ColB2, NULL AS ColB3
FROM * TableA
UNION ALL
SELECT NULL AS ColA1, NULL AS ColA2, NULL AS ColA3,
* * * *ColB1, ColB2, ColB3
FROM * TableB;

How to embed this in DTS is beyond me, for I never used DTS. But I
assume you can just call this query from DTS and get the results.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog:http://sqlblog.com/blogs/hugo_kornelis
Hi Hugo Kornelis, thnx for u r reply ur suggestion works.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.