dbTalk Databases Forums  

Problem Using INITCAP function

microsoft.public.sqlserver.server microsoft.public.sqlserver.server


Discuss Problem Using INITCAP function in the microsoft.public.sqlserver.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dwizz
 
Posts: n/a

Default Problem Using INITCAP function - 04-03-2006 , 05:41 AM






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


Reply With Quote
  #2  
Old   
Andy Price
 
Posts: n/a

Default RE: Problem Using INITCAP function - 04-03-2006 , 07:58 AM






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:

Quote:
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



Reply With Quote
  #3  
Old   
Dwizz
 
Posts: n/a

Default Re: Problem Using INITCAP function - 04-03-2006 , 08:08 AM



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:
Quote:
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




Reply With Quote
  #4  
Old   
Andy Price
 
Posts: n/a

Default Re: Problem Using INITCAP function - 04-03-2006 , 08:20 AM



I see, I didnt realize they were all in uppercase. You could change it to use
that, or you can just change your code to this (ie, added 1 line of code
prior to the block of code in the last post). INITCAP doesnt exist in SQL
Server. I am assuming you are an ORACLE or MySQL guy also?


set @CurrentCharacter =
LOWER(@CurrentCharacter)
IF @counter = 1 SET @CurrentCharacter = UPPER(@CurrentCharacter)
SET @counter = @counter + 1
SET @AddressLine1 = @AddressLine1 + @CurrentCharacter

--
Andy Price,
Sr. Database Administrator,
MCDBA 2003


"Dwizz" wrote:

Quote:
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





Reply With Quote
  #5  
Old   
Dwizz
 
Posts: n/a

Default Re: Problem Using INITCAP function - 04-03-2006 , 08:45 AM



Thanks Andy,
We got it to work, the extra line did it, I am indeed an Oracle man
Thanks once again Andy

Dhwiren


Reply With Quote
  #6  
Old   
Dwizz
 
Posts: n/a

Default Re: Problem Using INITCAP function - 04-03-2006 , 11:27 AM



Ahhh.. Andy, I just noticed that its the second character that becomes
Capitalised and not the first, but as a bonus all the other characters
are in lower case. So how would I make the first character Capitalised
and not the second character capitalised


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.