Many clients require data to be sent to them in various formats. Some require fixed length while others require delimited files. Whatever the case may be the contents of the file also vary. Some may want you to send date information in mm/dd/yy and others yet want to see it as mmddy. SQL Server has many built in conversion that will accomplish this, but as i came to find out with my most recent client request, some are just not available. This being the case i came up with this function which will allow you to pass what format you need your date to be and have it converted for you. My situation was the client wanted to have the date as mmddyy so after creating the function i tested it and eureka!! Call the function as follows: Select dbo.fnDateFormat(getdate(),'mmddyy') The function also allows for special characters such as / and -.
This function allows for a much cleaner code since i am using bcp to generate the fixed length file i wanted to save time and space in my code by not having to write all the code out in a statement, which as we all know, can get very lenghty and confusing.
Hope this is benefical to all. Enjoy!!