Category Archives: SQL

Selecting a specific number of rows in TSQL

The other day I had the need to select an exact number of rows in a TSQL stored procedure. The circumstances constrained me in multiple ways and I just so happened to come across this little gem of a trick for selecting a set number of rows without using TOP.

All one must do is use the following assigment:

1
SET @@ROWCOUNT = # OF ROWS TO SELECT

Then perform the select statement and your in business!

Insert Multiple TSQL Rows

The only easy way to insert multiple records in TSQL (and it's quick!):

1
2
3
4
INSERT INTO TableName(COLUMNS...)
SELECT Val1, Val2...
UNION ALL
SELECT Val1, Val2...

etc.