Monday, November 9, 2009

T-SQL 'STR' Function Notes

If you recieve the SQL error message:
Error converting data type varchar to float
The above error message is basically telling you that it can't convert your varchar data to a numeric value first, before it converts it back from numeric to varchar form.

Check to make sure that you're not improperly using the STR function on data that is already in varchar form. This function is for converting numeric data to string format, and I often use it as follows:
This pattern compensates for the STR function's inane tendancy to pad its output, and is useful if you like to see your data formatted as if you called a ".ToString" method (like as in the C# world).

No comments:

Post a Comment