• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

SQL quick help

rh71

No Lifer
How do I trim data since we have fields that are char(15) and the source is char(60) ? I want to pull only the first 15 chars from the source within the SELECT statement. TRIM seems to want a specific string to cut out.
 
You need to always tell us what platform, because it's quite different between them. I'm going to assume SQL Server of Access. It's ltrim() and rtrim() for SQL Server, and Trim() for Access.
 
substr sounds like it would be used to get portions from within a string, whereas left/right just grab from the left or right based on a length. substr will work though.
 
Originally posted by: WannaFly
If only there was a category for programming questions....man, life would be sweet then.
Pepsi, is that you? 🙂 NObody checks that forum quick enough if you need help pronto!
 
Originally posted by: Skoorb
Originally posted by: WannaFly
If only there was a category for programming questions....man, life would be sweet then.
Pepsi, is that you? 🙂 NObody checks that forum quick enough if you need help pronto!
Yup. It's not like programmers can sit and wait for a response either when trying to debug.

Alright, this sucks... instead of dropping the table and recreating... who knows how to alter the datatype of a column ?

Tried ALTER TABLE tablename ALTER COLUMN columnname SET DATA TYPE CHAR(140) and it won't accept it. :|
 
Well it will only alter if the data within it will be compatible with the new type; ie, if you've got a char(15) and the column is full of 15 length strings you can't go down to (8). You can try a varchar type, to allow variable length strings - that may help you.
 
it's completely blank right now... even dropped the view against it first. (as a learning experience, I'm trying to alter instead of drop/recreate)

The error I'm getting is a syntax problem.

(it's take ATOT to work day) 😀
 
Originally posted by: rh71
it's completely blank right now... even dropped the view against it first. (as a learning experience, I'm trying to alter instead of drop/recreate)

The error I'm getting is a syntax problem.

(it's take ATOT to work day) 😀
That sucks, that's why I use enterprise manager (GUI) within sql server when I edit tables; saves me having to learn the raw SQL 😀
 
Originally posted by: Skoorb
Originally posted by: rh71
it's completely blank right now... even dropped the view against it first. (as a learning experience, I'm trying to alter instead of drop/recreate)

The error I'm getting is a syntax problem.

(it's take ATOT to work day) 😀
That sucks, that's why I use enterprise manager (GUI) within sql server when I edit tables; saves me having to learn the raw SQL 😀
I would rather not rip on DB2 Control Center, but... 😉
 
Originally posted by: rh71
Originally posted by: Skoorb
Originally posted by: WannaFly
If only there was a category for programming questions....man, life would be sweet then.
Pepsi, is that you? 🙂 NObody checks that forum quick enough if you need help pronto!
Yup. It's not like programmers can sit and wait for a response either when trying to debug.

Alright, this sucks... instead of dropping the table and recreating... who knows how to alter the datatype of a column ?

Tried ALTER TABLE tablename ALTER COLUMN columnname SET DATA TYPE CHAR(140) and it won't accept it. :|

To be fair, there are hundreds of other more appropriate forums for programming. There are mailing lists, news groups, forums, etc.

Your syntax looks right from what I can tell. Can you post the actual SQL statement?
 
Back
Top