Wednesday, April 27, 2005

Sort randomly

To sort radomly every time you run the query, use this method,

SELECT columnname1, columnname2 FROM YOURTABLE ORDER BY NEWID()

Days of the month using SQL

To find the days in a month using SQL, use the following method. Here TSQL syntax is used for example.

--------------------

DECLARE @Date datetime
SET @Date = '2000/02/1'
SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 1),@Date) AS 'First day of the week'
SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 7),@Date) AS 'Last day of the week'
SELECT DAY(DATEADD(d, -DAY(DATEADD(m,1,@Date)),DATEADD(m,1,@Date))) AS 'Last day of the month'
--------------------

for more sql tricks goto.. Extremeexperts