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.
The where condition is:
WHERE Items.ItemType = 'VAR" and Order.CVSFlag = '0'
After the above is done then
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.