Two tips for MsSQL Server

SQL server
  • To check if string contains another string starting from SQL Server 2005 we can do it this way:
    SELECT * FROM tableName WHERE CHARINDEX('SUB', fieldName) > 0
  • To get a specific range of rows from a query - do it this way:
    SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY ID) as row FROM tableName) a WHERE row >0 and row <= 10
    This select will retrieve the first 10 records.

Post a Comment

Previous Post Next Post