MS SQL

ms-sql-sql

Round A Number In MS SQL

10th November 2008

To round a number in MS SQL use the ROUND() function. This function takes two parameters, the first is the number to be rounded and the second is the number of decimal places to round the number to. Here is an example of rounding the numbers in a column to the nearest whole integer.

Concatenate Strings In MS SQL

7th November 2008

If you want to concatenate the output of three different columns in MS SQL just use the + symbol.

Limit Number Of Rows Returned In MS SQL

23rd September 2008

To limit the number of rows returned in a MS SQL query you need to use the TOP command. This goes before you name the columns that are to be returned by the SELECT statement.

The following query returns the first 35 rows from a table.

Getting A Random Row From A MS SQL Table

9th January 2008

To get a random row from a Microsoft SQL database you need to use the NEWID() function. This will generate a new random number for each row and order them by that new number. This is used in conjunction with the TOP clause to limit the amount of returned rows to one.