valeryk2000 (6/27/2013)
Ha! Sean, you elegantly rewrote my function (stollen from somwhere anyway).I do not think that to use cte in my case is a good idea - I use this function within a select statement from a big table - not sure that cte can be used here
The only reason there is a cte there is for testing. I don't have a table with the values you posted so I just stuck them in a cte. It is merely an example of usage. That could a table, a cte, whatever.
They way you wrote the function and are using it is a scalar function. They are horrible for performance. Look at how I used the iTVF with cross apply instead of calling the function as a column. The performance benefits are HUGE!!!!
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/