Never underestimate the power of the dark side
September 12, 2008 – 8:58 amSQL optimization is the red lightsaber of the application development world. It’s what separates the posers from the developers.
On an application I was working on, one web page was taking over 2 minutes (120 seconds) to load. Ack.
After a few tweaks to a table function (FWIW: SQL2005’s table functions are the bomb), that is down to 4 seconds.
In my opinion, table functions could be used to functionally replace the traditional SQL view in many cases - especially those where the view returns a lot of data.
They are treated in queries just like tables:
select * from dbo.myTableFunction()
In addition, you can pass in parameters to limit the results, like this:
select * from dbo.myTableFunction(@someParam)
But in my case, what makes them absolutely rock is that you can do this:
declare @filteredRows TABLE (id int, type varchar(10)) insert into @filteredRows (landTransactionID) select ScalarId from dbo.stringSplit(@transIds)
Now, you can join to that variable just like it was a table - so if you need the results multiple times, you get them, but only have to pay for them once.
Long live SQL!


