troubleshooting Question

Need help building a SQL statement & DTS to export records to an excel csv file.

Avatar of eddiepardon
eddiepardon asked on
Microsoft SQL Server
7 Comments2 Solutions244 ViewsLast Modified:
Hello Experts,

I am not sure exactly where to being. Maybe with the end in mind is the best.

End product should be one or maybe many csv files based upon the ItemNum which is stored in Items.ItemNum. CSV naming conventions needs to be the ItemNum + _ + the name of the xml file that the original data was imported into the database with. The XML is named like 20062161114.xml and is stored in the database in Orders.OrderXMLFilename. So the output file will be 383_20062161114.csv.

The part I am struggling with is how to construct the sql statement to pull the data.

I have created a field in the orders table named CVSFlag bit, null to ensure that duplicates do not get exported. The flag will have to be updated.

Below is the data I need to pull and the order it needs to populate the csv file.


Requestor.userName
Requestor.OrderID
Orders.RequestorFirstname
Orders.RequestorLastname
Orders.RequestorAddressLine1
Orders.RequestorAddressLine2
Orders.RequestorAddressLine3
Orders.RequestorCity
Orders.RequestorState
Orders.RequestorPostalCode
Orders.RequestorPhoneNumber
Orders.RequestorEmail
Orders.RequestorCostCenter
Recipients.Firstname
Recipients.Lastname
Recipients.AddressLine1
Recipients.AddressLine2
Recipients.AddressLine3
Recipients.City
Recipients.State
Recipients.PostalCode
Recipients.Country
Orders.ShippingCompany
Orders.ShippingService
Orders.ShippingAddressee
Orders.ShippingAddressLine1
Orders.ShippingCity
Orders.ShippingState
Orders.ShippingPostalCode
OrderItems.ItemID
OrderItems.Quantity
OrderItemElements.OrderItemElementValue
Orders.OrderXmlFilename
Items.ItemType
Items.ItemID
Orders.OrderID

The where condition is:
WHERE Items.ItemType = 'VAR" and Order.CVSFlag = '0'

After the above is done then
UPDATE Order
SET CSVFlag = '1'

I realize I may not have given enough information, If you need more please ask and I will provide it.

Thanks in advance.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros