Friday, December 24, 2010

Random Date Generator

SELECT DATEADD(day, DATEDIFF(day, 0, GETDATE()) - 1 - FLOOR(RAND(CAST(NEWID() AS binary(4))) * 365.25 * 10), 0)

Number 10 is the year range, for example, if you want dates from recent to 10 years before, select 10.

Monday, November 15, 2010

find last word in string

SELECT RIGHT(Address1,COALESCE(NULLIF(CHARINDEX(' ', REVERSE(Address1)) - 1,-1),LEN(Address1)))

Wednesday, October 27, 2010

Logfile Space Usage on Server

If you want to see how much log file space is free for each database on the server, use the following

DBCC sqlperf(logspace)

Friday, October 15, 2010

Enable xp_cmdshell

sp_configure 'show advanced options',1
reconfigure
sp_configure 'xp_cmdshell',1
reconfigure

Friday, September 3, 2010