Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin.
Search for scripts directly from SSMS, and instantly access any saved scripts in your
SSC briefcase from the favorites tab.
Download now (direct download link)
Thank this author by sharing:
By Ervin Santiago,
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!!
functions causing query to run excessively long
A function for getting Client IP Address in SQL Server
Max allowed length for value returned using RETURN in a user defined function
Query / increment counters by concurrent ADO clients