SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 string adding problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bill_
Starting Member

37 Posts

Posted - 09/18/2013 :  10:21:38  Show Profile  Reply with Quote
This prints the 10 lines a_,...,a_
but want it to print the 10 lines a_1, a_2, a_3, ..., a_10
What is the error?

declare @ex varchar(4)
set @ex='a_'
while @ind<11 --starts at 1
   begin
      set @ex=@ex+str(@ind)
      print @ex
      @ind=@ind+1
   end

khtan
In (Som, Ni, Yak)

Singapore
17635 Posts

Posted - 09/18/2013 :  10:28:28  Show Profile  Reply with Quote
declare @ex varchar(4)
set @ex='a_'
while @ind<11 --starts at 1
   begin
      set @ex=@ex+convert(varchar(2), @ind)
      print @ex
      select @ind=@ind+1
   end



KH
Time is always against us


Edited by - khtan on 09/18/2013 10:43:09
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30242 Posts

Posted - 09/18/2013 :  10:39:47  Show Profile  Visit SwePeso's Homepage  Reply with Quote
STR functions defaults at one character.

+STR(@ind)

should be

+STR(@ind, 2) -- or more characters



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

bill_
Starting Member

37 Posts

Posted - 09/25/2013 :  15:32:44  Show Profile  Reply with Quote
Thank you. Convert() helped.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000