Friday, 28 June 2013

Query to Get Records of last n days from table in Sql Server 2008

Try this Sql Query to get all the record of yesterday.......or last 15 days record or last n days records......

"select * from tablename WHERE CONVERT(VARCHAR(10),colname, 112)>= CONVERT(VARCHAR(10),DATEADD(DAY,-(n-1),GETDATE()), 112)"

Query to remove last comma/character in column update in sql server

Try this sql query to update data of column as remove last comma from column value..........

" UPDATE tablename
SET colname= LEFT(colname, len(colname) -1)
WHERE RIGHT(colname,1) = ',' "