Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
saiabhiram
Starting Member
17 Posts |
Posted - 2010-04-15 : 17:27:01
|
| Hello,I need to loop thru alphanumeric values in a Sql Server Stored Procedure below:'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'We dont have arrays in Sql Server. Can you guys tell me how I can go about this. It would be great if you guys can be more specific as I dont have much database programming experience.Thanking You in Anticipation, |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-04-15 : 17:35:28
|
This should help:DECLARE @str VARCHAR(50)DECLARE @pos INT SET @str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'SET @pos = 1WHILE @Pos <= LEN(@str)BEGIN PRINT SUBSTRING(@str, @pos, 1) SET @pos = @pos + 1END ------------------------------------------------------------------------------------Any and all code contained within this post comes with a 100% money back guarantee. |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-04-16 : 02:46:41
|
No need for looping through the valuesTry this toDECLARE @str VARCHAR(50)DECLARE @pos INT SET @str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'select SUBSTRING(@str,number,1)as value from master.dbo.spt_values where type='p'and number between 1 and LEN(@str) PBUH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-04-16 : 04:54:33
|
quote: Originally posted by Idera No need for looping through the valuesTry this toDECLARE @str VARCHAR(50)DECLARE @pos INT SET @str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'select SUBSTRING(@str,number,1)as value from master.dbo.spt_values where type='p'and number between 1 and LEN(@str) PBUH
You dont need variable @pos. I think it may be due to copy/paste from previous code MadhivananFailing to plan is Planning to fail |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-04-16 : 05:14:07
|
quote: Originally posted by madhivanan
quote: Originally posted by Idera No need for looping through the valuesTry this toDECLARE @str VARCHAR(50)DECLARE @pos INT SET @str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'select SUBSTRING(@str,number,1)as value from master.dbo.spt_values where type='p'and number between 1 and LEN(@str) PBUH
You dont need variable @pos. I think it may be due to copy/paste from previous code MadhivananFailing to plan is Planning to fail
Yes thats right PBUH |
 |
|
|
|
|
|