Thursday, August 7, 2008

REPLICATE function

Repeats a string value a specified number of times.

Syntax:
REPLICATE ( string , integer)
string - what should be repeated or added
integer - how many times string value should be repeated

Example:
select REPLICATE('0',2)+[Product_Code] from Products

The above query will return the product code value with 2 zeroes added at the first.
If product code is PCT then the result will be 00PCT