Replicate Function In SQL Server 2008

Replicate() function is inbuilt function in SQL Server 2008 that can be used to append (replicate) characters in a particular string or values of given column. This function is mainly used in situations when user needs to make sure that all data in given column should be of fixed length. Replicate function is the best way to fix this problem.

Syntax

REPLICATE (string_expression, integer expression )

where,

string_expression- specifies character string or binary data that you want to append before the string or a number

integer_expression- It decides how many times the string_expression is to be appended.

Example

Suppose you have table named Employee having columns (id, F_Name, L_Name, Salary, City, Region) shown in below image.

Table-in-sql.jpg

For applying replication, type following code:

Output:

ReplicateFunction-in-sql.jpg


Reference:http://www.dotnetheaven.com/article/replicate-function-in-sql-server-2008

你可能感兴趣的:(replicate)