TSQL Functions you wish existed

Posted by Dave @ EHS Tue, 03 Oct 2006 21:53:00 GMT

Ever dismayed by the lack of seemingly obvious functions that TSQL just doesn't seem to have? Well here is a fantastic collection of user defined functions to complete an impressive array of tasks.

rand() in TSQL isn't random at all!

Posted by Dave @ EHS Thu, 14 Sep 2006 15:54:00 GMT

Trying to return a query with a random sort order from TSQL I thought the most obvious
way would be like this:


SELECT *
FROM Northwind..Customers
order by rand()

However for a multi line select statement the value of rand() will be the same for each
row.

This article here has a neat work around with a custom view and a custom function.

However a colleague rightly pointed out that this will do the trick.

SELECT *
ROM Northwind..Customers
order by newid()

 

Thanks Val!