A function to convert varbinary to hex string. Have you every tried to deal with varbinary via T-SQL? Passwords and SIDs are of this datatype. In Query Analyzer this datatype displays as hex string but under the hood it is binary. Try concatenating a varbinary to a string in a print statement and you get a datatype mismatch error. Try to convert this datatype to varchar and you get garbage. You can use the little know extended stored procedure xp_varbintohexstr. It takes one varbinary input parameter and outputs the equivalent hex string as an OUTPUT parameter but it is not well suited for set processing. Ufn_vbintohexstr is. You can use it directly in a select statement against a column if necessary. Remember to include the parentheses when using this function in a select statement but don't include them when calling it via Exec. The input is a varbinary(256) so any length variable up to this max can be converted. The function returns the equivalent hex string of the varbinary input value. BTW a hex string doesn't convert back into a varbinary via the convert function so take care using the results and don't forget to include 2 extra position for the leading '0x' in your output variables. -- Fast & efficient update to original.
A short but interesting article, the author has figured out a way to create a PDF from a stored procedure without using a third party library.