• We should now be fully online following an overnight outage. Apologies for any inconvenience, we do not expect there to be any further issues.

SQL quick help

rh71

No Lifer
Aug 28, 2001
52,844
1,049
126
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.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
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.
 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
LEFT is the function you want, and you can do a quick search on google for the syntax to use!
 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
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.
 

KLin

Lifer
Feb 29, 2000
30,430
747
126
yes, substr() is what you want to only select a portion of a field for query/400
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
If only there was a category for programming questions....man, life would be sweet then.
 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
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!
 

rh71

No Lifer
Aug 28, 2001
52,844
1,049
126
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. :|
 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
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.
 

rh71

No Lifer
Aug 28, 2001
52,844
1,049
126
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) :D
 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
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) :D
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 :D
 

rh71

No Lifer
Aug 28, 2001
52,844
1,049
126
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) :D
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 :D
I would rather not rip on DB2 Control Center, but... ;)
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
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?