Let’s carry on from that point and work on our header. We are sending this file to another system so we need to tell it some information about us. First of all the header line will start with an “H”. Next it will have some information about our company so we will put in our company name, left justified in 20 spaces with excess spaces being filled with blanks. Next we will put the Julian Date. Add one space. Then we will put a sequence number that changes each time we produce this file. To do this we will set up a parameter. This number will occupy 7 spaces and be proceeded by zeros on the left. Add one space. Finally we will put a code of characters that represents our unique company’s account number.
When we execute our stored procedure we see the window that asks us for our parameter value. Itis shown below. Here the user has entered in the number 47. At the bottom of this window there is an OK button that the user clicks to get the results.
Our stored procedure code is shown below. Again, some of the comments and a few spaces have been removed.
I have added one more record to the flat csv file just to test it a little further. Below is the result file in SQL Server. It is still producing one trailer line for each detail line, however.