Jul 17, 2002 #1 snyderj MIS Joined Mar 2, 2001 Messages 242 Location 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.
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.
Jul 17, 2002 1 #2 bjd4jc Programmer Joined Nov 8, 2001 Messages 1,627 Location US 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 Upvote 0 Downvote
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
Jul 18, 2002 1 #3 tlbroadbent MIS Joined Mar 16, 2001 Messages 9,982 Location US Use the Replicate function. 'ABC' + REPLICATE('0',10-LEN(@variable)) + @variable Terry L. Broadbent - DBA Computing Links: http://tlbroadbent.home.attbi.com/prog.htm faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions. Upvote 0 Downvote
Use the Replicate function. 'ABC' + REPLICATE('0',10-LEN(@variable)) + @variable Terry L. Broadbent - DBA Computing Links: http://tlbroadbent.home.attbi.com/prog.htm faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.