Lowell (12/11/2012)
no insults, just help with the logical rules of thumb for procedures and functions:avoid loops whenever possible: that's cursor, while loops whatever;
Additionally
Avoid data access in a scalar UDF unless there's no other possible way to do what you need.
Avoid scalar UDFs that will be used in the select statement of large queries, SQL calls them once per row.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability