Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a command in SQL Server 2K 2

Status
Not open for further replies.

snyderj

MIS
Mar 2, 2001
242
US
Is there a command in SQL Server 2K similar to Excel's REPT command? I'm thinking of something such as:
'ABC' + REPT(0,10-LEN(@variable)) + @variable

so that ABC123 becomes ABC0000000123.

Thanks.
 
I did this in the SQL Query Analyzer. It is not exactly the same but it does what you want.
Code:
Declare @Variable int

set @Variable=1234

Print Len(@Variable)

PRINT STUFF('ABC' + cast(@variable As Varchar(10)), Len('ABC')+1, 0, REPLACE(SPACE(10-Len(@Variable)),' ', '0'))

You can adapt this to your stored procedure or whatever
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top