Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Extracting data

Author  Topic 

Calleman87
Starting Member

2 Posts

Posted - 2014-08-22 : 07:23:39
Hi all!

New to all this SQL-thing. I'm running a joint company with a friend of mine and we are trying to extract a bunch of data from our tables.
I've managde to retrieve the data that we want out of an order table, but I can't make it export the way I want.

We have two tables with information that we want to extract.

The code we've written looks like this:

"SELECT o.id_order, o.reference, o.id_customer, o.payment, od.id_order_detail
FROM ps_orders o
LEFT JOIN ps_order_detail od ON (od.id_order = o.id_order)"

It gives us a result that looks like this:
8 12345 78 PayPal ProductName
8 12345 78 PayPal ProductName
8 12345 78 PayPal ProductName
9 12789 60 PayPal ProductName
9 12789 60 PayPal ProductName
9 12789 60 PayPal ProductName

So extracting the data is not an issue (from what I feel) I would like it to be:

8 12345 78 Paypal
ProductName
ProductName
ProductName
9 12789 60 PayPal
ProductName
ProductName
ProductName

What code would you recommend me to use to export the data in the format written above?

Thank you in advance!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-08-22 : 12:25:37
This should be handled by the application layer, whether it be your program or a report. Return raw data from SQL, and let the application layer handle the formatting.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Calleman87
Starting Member

2 Posts

Posted - 2014-08-22 : 13:32:30
Hi Tara!

Thanks for replying! I'm not really sure what you mean by application layer, but I'm taking a wild guess here, (after all, as an accountant by trade, I must be forgiven, right? ;)) the application which will be used to import into is of strict format. The manufacturer of the program clearly specifies that an import .csv file should be arranged in a certain order, otherwhise the import will fail. Hence the need to extract data from database and present it in a certain order. What i'm asking about is non-achievable?
Go to Top of Page
   

- Advertisement -