SQL Server: UPDATE a table by using ORDER BY

No. Not a documented 100% supported way. There is an approach sometimes used for calculating running totals called “quirky update” that suggests that it might update in order of clustered index if certain conditions are met but as far as I know this relies completely on empirical observation rather than any guarantee. But what version … Read more

Find index of last occurrence of a sub-string using T-SQL

Straightforward way? No, but I’ve used the reverse. Literally. In prior routines, to find the last occurence of a given string, I used the REVERSE() function, followed CHARINDEX, followed again by REVERSE to restore the original order. For instance: SELECT mf.name ,mf.physical_name ,reverse(left(reverse(physical_name), charindex(‘\’, reverse(physical_name)) -1)) from sys.master_files mf shows how to extract the actual … Read more

Storing files in SQL Server

There’s a really good paper by Microsoft Research called To Blob or Not To Blob. Their conclusion after a large number of performance tests and analysis is this: if your pictures or document are typically below 256K in size, storing them in a database VARBINARY column is more efficient if your pictures or document are … Read more