![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hey all, I'm trying to use the INITCAP function to make the first letter of an address appear in capital and the rest in lower case, but it seems to appear all in Caps. Can anyone please help. I've attached a snipplet of the code. TIA Dhwiren DECLARE @counter smallint DECLARE @counterLimit smallint DECLARE @RandomNumber float DECLARE @RandomNumberInt tinyint DECLARE @CurrentCharacter varchar(1) DECLARE @ValidCharacters varchar(255) DECLARE @ValidCharactersLength int DECLARE @DEBUG int SET @ValidCharacters = 'aaabcdeeefghiiijklmnooopqrstuuuvwxyz' SET @ValidCharactersLength = len(@ValidCharacters) SET @CurrentCharacter = '' SET @RandomNumber = 0 SET @RandomNumberInt = 0 SET @DEBUG=1 -- @AddressLine1 SET @counter=0 SET @counterLimit = len(@AddressLine1) IF @counterLimit>0 BEGIN SET @AddressLine1='' WHILE @counter < @counterLimit BEGIN -- create a random sting SET @RandomNumber = Rand() SET @RandomNumberInt = Convert(tinyint, ((@ValidCharactersLength - 1) * @RandomNumber + 1)) SELECT @CurrentCharacter = SUBSTRING(@ValidCharacters, @RandomNumberInt, 1) IF @counter = 1 SET @CurrentCharacter =(@CurrentCharacter) SET @counter = @counter + 1 SET @AddressLine1 = @AddressLine1 + INITCAP(@CurrentCharacter) END IF @DEBUG=1 PRINT @AddressLine1 END |
#3
| |||
| |||
|
|
i havent ran the code, but your logic is slightly flawed. change the end part to something like this. You can also use UPPER in place of INITCAP in your code because you are pulling 1 character at a time from SUBSTRING. IF @counter = 1 SET @CurrentCharacter = UPPER(@CurrentCharacter) SET @counter = @counter + 1 SET @AddressLine1 = @AddressLine1 + @CurrentCharacter -- Andy Price, Sr. Database Administrator, MCDBA 2003 "Dwizz" wrote: Hey all, I'm trying to use the INITCAP function to make the first letter of an address appear in capital and the rest in lower case, but it seems to appear all in Caps. Can anyone please help. I've attached a snipplet of the code. TIA Dhwiren DECLARE @counter smallint DECLARE @counterLimit smallint DECLARE @RandomNumber float DECLARE @RandomNumberInt tinyint DECLARE @CurrentCharacter varchar(1) DECLARE @ValidCharacters varchar(255) DECLARE @ValidCharactersLength int DECLARE @DEBUG int SET @ValidCharacters = 'aaabcdeeefghiiijklmnooopqrstuuuvwxyz' SET @ValidCharactersLength = len(@ValidCharacters) SET @CurrentCharacter = '' SET @RandomNumber = 0 SET @RandomNumberInt = 0 SET @DEBUG=1 -- @AddressLine1 SET @counter=0 SET @counterLimit = len(@AddressLine1) IF @counterLimit>0 BEGIN SET @AddressLine1='' WHILE @counter < @counterLimit BEGIN -- create a random sting SET @RandomNumber = Rand() SET @RandomNumberInt = Convert(tinyint, ((@ValidCharactersLength - 1) * @RandomNumber + 1)) SELECT @CurrentCharacter = SUBSTRING(@ValidCharacters, @RandomNumberInt, 1) IF @counter = 1 SET @CurrentCharacter =(@CurrentCharacter) SET @counter = @counter + 1 SET @AddressLine1 = @AddressLine1 + INITCAP(@CurrentCharacter) END IF @DEBUG=1 PRINT @AddressLine1 END |
#4
| |||
| |||
|
|
Thank you for the quick reply Andy, I am pulling 1 character out at a time but in the database they are all uppercase, which is why I was wondering using INITCAP Dhwiren Andy Price wrote: i havent ran the code, but your logic is slightly flawed. change the end part to something like this. You can also use UPPER in place of INITCAP in your code because you are pulling 1 character at a time from SUBSTRING. IF @counter = 1 SET @CurrentCharacter = UPPER(@CurrentCharacter) SET @counter = @counter + 1 SET @AddressLine1 = @AddressLine1 + @CurrentCharacter -- Andy Price, Sr. Database Administrator, MCDBA 2003 "Dwizz" wrote: Hey all, I'm trying to use the INITCAP function to make the first letter of an address appear in capital and the rest in lower case, but it seems to appear all in Caps. Can anyone please help. I've attached a snipplet of the code. TIA Dhwiren DECLARE @counter smallint DECLARE @counterLimit smallint DECLARE @RandomNumber float DECLARE @RandomNumberInt tinyint DECLARE @CurrentCharacter varchar(1) DECLARE @ValidCharacters varchar(255) DECLARE @ValidCharactersLength int DECLARE @DEBUG int SET @ValidCharacters = 'aaabcdeeefghiiijklmnooopqrstuuuvwxyz' SET @ValidCharactersLength = len(@ValidCharacters) SET @CurrentCharacter = '' SET @RandomNumber = 0 SET @RandomNumberInt = 0 SET @DEBUG=1 -- @AddressLine1 SET @counter=0 SET @counterLimit = len(@AddressLine1) IF @counterLimit>0 BEGIN SET @AddressLine1='' WHILE @counter < @counterLimit BEGIN -- create a random sting SET @RandomNumber = Rand() SET @RandomNumberInt = Convert(tinyint, ((@ValidCharactersLength - 1) * @RandomNumber + 1)) SELECT @CurrentCharacter = SUBSTRING(@ValidCharacters, @RandomNumberInt, 1) IF @counter = 1 SET @CurrentCharacter =(@CurrentCharacter) SET @counter = @counter + 1 SET @AddressLine1 = @AddressLine1 + INITCAP(@CurrentCharacter) END IF @DEBUG=1 PRINT @AddressLine1 END |
#5
| |||
| |||
|
#6
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |