473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can I do this in SQL Analyzer or with a dts package?

I am not sure how to approach this problem or if I can even do it
within SQL.

Say I have 2 tables invoice_hdr and invoice_dtl. I want to pull
specific fields from both tables, I want the data to be grouped
together however I want the information to be on different lines. One
for the information from the header and one for each corresponding
detail record.

So my output might look like

Invoice_number (1), Invoice_date, Customer_Number
Item_number (1-1), qty, price, description
Item_number (1-2), qty, price, description

Invoice_number (2), Invoice_data, Customer_number
Item_number (2-1), qty, price, description
Item_number (2-2), qty, price, description
Item_number (2-3), qty, price, description

etc..
So the invoice_number (1) is my first invoice and item_number (1-1)
would be the 1st item on tins invoice, etc...

My ultimate goal is to export this to a text or csv file.
Thanks.

Mar 1 '06 #1
2 1220
Hi Mike,

It can be done in a SQL stored proc but it will get kind of ugly. Basically
it sounds like you are taking two tables and trying to return one result set
(with 1 schema) or maybe just one text (varchar) column with all the data
written and concatenated as text.

Using VB Script, or a console application written in C, VB.Net or something
you could have your stored proc return two result sets in Invoice Number
order and then create the text (CSV file) by marching through the two
recordsets (if you are using ADO) and outputing records to your text file in
the application that calls the stored proc.

If you use VB Script you could put that in a DTS Package, Call the stored
proc and create the output file.

What is the schema of invoice_hdr and invoice_dtl?

-Dick Christoph
"mike" <mi********@gmail.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
I am not sure how to approach this problem or if I can even do it
within SQL.

Say I have 2 tables invoice_hdr and invoice_dtl. I want to pull
specific fields from both tables, I want the data to be grouped
together however I want the information to be on different lines. One
for the information from the header and one for each corresponding
detail record.

So my output might look like

Invoice_number (1), Invoice_date, Customer_Number
Item_number (1-1), qty, price, description
Item_number (1-2), qty, price, description

Invoice_number (2), Invoice_data, Customer_number
Item_number (2-1), qty, price, description
Item_number (2-2), qty, price, description
Item_number (2-3), qty, price, description

etc..
So the invoice_number (1) is my first invoice and item_number (1-1)
would be the 1st item on tins invoice, etc...

My ultimate goal is to export this to a text or csv file.
Thanks.

Mar 1 '06 #2
If you are pushing this through some sort of parser, grid, asp page,
etc., here's what I usually do...

1) Use correlated tables with two datasets. Google search for
that--some of the .net controls support it via nesting.

2) Return everything on every record. e.g.
Invoice_number (1), Invoice_date, Customer_Number, Item_number (1-1),
qty, price, description
Invoice_number (1), Invoice_date, Customer_Number, Item_number (1-2),
qty, price, description
Invoice_number (1), Invoice_date, Customer_Number, Item_number (1-3),
qty, price, description

Then when you display this, just check neighbor rows (pseudocode):

For Each Row
If PreviousRow.InvoiceNumber <> CurrentRow.InvoiceNumber Then
Output Header Row (invoicenum, date, cust num)
Output Detail row(item number, qty, price, description)
Else
Output Detail row(item number, qty, price, description)
End If
Next

Sure this approach returns some data you won't use for every row but it
is very easy to do, and involves just one record set.

You could presumably implement this approach or DickChristoph's idea in
a cursor, too.

Mar 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Warren Wright | last post by:
Hi group, I have a select statement that if run against a 1 million record database directly in query analyzer takes less than 1 second. However, if I execute the select statement in a stored...
1
by: Alex Cicco | last post by:
Hi, I am new to SQL. Please bear with me and allow me to ask a dumb question. I am debugging a stored procedure (written in Trans-SQL), and I found that the SQL analyzer that I use doesn't...
2
by: Poster | last post by:
After creating an IN clause from a bunch of character strings created by a Word macro, Query Analyzer complains about a syntax error. The macro takes a column full of character strings and wraps...
3
by: JM | last post by:
Good day. I was able to connect to a database server using SQL Server Enterprise Manager. The Server name specified on the tree is JOMARGON(Windows NT). But no server was detected using either...
1
by: justinjoylife | last post by:
Hi - I'm completely new to Microsoft Query Analyzer and I need to learn it for work to do data mining as a Product Manager. Does anyone have any recommendations on how to learn this and where?...
1
by: Chris Morse | last post by:
Does anyone know how to profile a VB.NET application? In the VS.NET 2003 docs, I found this: (BEGIN DOC COPY) "A code profiler is a software tool, implemented as a DLL, which is called by...
14
by: Kevin G. Anderson | last post by:
What: CAUG Meeting - QuickBooks IIF Files; Total Access Analyzer; CAUG Social When: Thursday, May 25, 2006, 6PM Who: Chris Monaghan and Kevin Anderson Where: The Information Management Group...
2
by: SQL Server Questions | last post by:
Environment: Server1 (Local) OS Windows 2000 Server SQL Server 2000 Server2 (Remote) OS Windows 2003 Server SQL Server 2000 (Both with most recent service packs)
0
by: blueblueblue | last post by:
Hi, I am trying to execute my dts package from sql using command shell as exec master..xp_cmdshell 'dtsrun /Sfiutopiadb /Usa /P /NBulktest' The package works perfectly in enterprise...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.