Modify length of string field

Questions about our Advanced Database plug-in

Moderator: Neosoft Support

Locked
User avatar
BRobinsonS
Posts: 355
Joined: Sun Sep 25, 2005 9:00 pm
Location: Ontario, Canada
Contact:

Modify length of string field

Post by BRobinsonS »

I have an application which allowed 35 characters for email address.
Of course, someone has to come up with an email longer than 35 characters.

Is there an elegant way to extend the length to 50 characters?
I have an idea but before I do that is there a way to determine the length first?

That is, if length is 35 then extend to 50 else take no action.
(this assumes the length would only need to be changed at once.)
Brian Robinson
'When all else fails, try again!'
www.ComputerSoftwareSystems.com
User avatar
Wrangler
Posts: 1531
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA
Contact:

Re: Modify length of string field

Post by Wrangler »

strlen in a conditional statement.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Modify length of string field

Post by Gaev »

Brian:
I have an application which allowed 35 characters for email address.
Of course, someone has to come up with an email longer than 35 characters.

Is there an elegant way to extend the length to 50 characters?
I am assuming that ...

- this is a text/string field
- you want to increase the length of the field (column)
- you are amenable to doing it while the Table is NOT Open (adding/editing other records)

... perhaps this suggestion ...

Code: Select all

ALTER TABLE YourTableNameHere
ALTER COLUMN YourColumnnameHere VARCHAR(50)
... that I found here ... https://stackoverflow.com/questions/152 ... -via-t-sql ... might help.
I have an idea but before I do that is there a way to determine the length first?
Pray tell us your idea.
That is, if length is 35 then extend to 50 else take no action.
(this assumes the length would only need to be changed at once.)
I'm confused.
User avatar
BRobinsonS
Posts: 355
Joined: Sun Sep 25, 2005 9:00 pm
Location: Ontario, Canada
Contact:

Re: Modify length of string field

Post by BRobinsonS »

Since I built SQL execution possibilities into the app, I was able use

Code: Select all

ALTER TABLE YourTableNameHere
ALTER COLUMN YourColumnnameHere VARCHAR(50)
successfully. Wasn't just for myself.

Now I can tell my customers how to change the length if required.
My idea was to use SQL if I could figure out how.
Now I have. I thought I would have to build the SQL into the code, but I don't have to.
Brian Robinson
'When all else fails, try again!'
www.ComputerSoftwareSystems.com
Locked