Showing posts with label difference. Show all posts
Showing posts with label difference. Show all posts

Saturday, 3 August 2013

SQL SERVER – DIFFERENCE BETWEEN CAST AND CONVERT(Cast vs Convert)

Both cast and covert serves the same purpose i.e. convert a data type to another.

  • Cast


  1. Cast is  ANSII Standard
  2. Cast cannot be used for Formatting Purposes.
  3. Cast cannot convert a datetime to specific format


  • Convert


  1. Convert is Specific to SQL SERVER
  2. Convert can be used for Formatting Purposes.For example Select convert (varchar, datetime, 101)
  3. Convert can be used to convert a datetime to specific format

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)"