| Author |
Topic |
|
baze7
Yak Posting Veteran
58 Posts |
Posted - 2010-02-02 : 11:38:54
|
| I have an issue. I am trying to insert a number into a sql field that is requiring a length of 7. Example ' 7'Here an example:values( 'E','SQL0000002',' 7','W'Is there a way to just use '7' instead, other than using ' 7'Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-02 : 11:45:32
|
| use LTRIM (' 7') |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2010-02-02 : 11:49:47
|
| Why are you padding number with spaces?Harsh Athalyehttp://www.letsgeek.net/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-02 : 11:51:37
|
quote: Originally posted by harsh_athalye Why are you padding number with spaces?Harsh Athalyehttp://www.letsgeek.net/
i guess it may be for illustrative purpose. may be his actual value comes from another column |
 |
|
|
baze7
Yak Posting Veteran
58 Posts |
Posted - 2010-02-02 : 12:03:24
|
| My issue, I belive what is happening is then I insert this into the SQL field it is validating that the cust_num exists. And if it is just '7' it errors out, but if it is ' 7' it works fine. So I need to somehow add the spaces before it or something. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-02 : 12:14:00
|
quote: Originally posted by baze7 My issue, I belive what is happening is then I insert this into the SQL field it is validating that the cust_num exists. And if it is just '7' it errors out, but if it is ' 7' it works fine. So I need to somehow add the spaces before it or something.
if you want to pad spaces just useSTUFF(column,1,0,' ') |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2010-02-02 : 13:21:36
|
quote: Originally posted by baze7 My issue, I belive what is happening is then I insert this into the SQL field it is validating that the cust_num exists. And if it is just '7' it errors out, but if it is ' 7' it works fine. So I need to somehow add the spaces before it or something.
In that case, may be you should try to trim the values before checking whether it exists or not. If that is out of your control, then Visakh's solution should work or you may do LIKE comparison but that would be costly in terms of performance.Harsh Athalyehttp://www.letsgeek.net/ |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-02-02 : 15:37:46
|
quote: Originally posted by baze7 My issue, I belive what is happening is then I insert this into the SQL field it is validating that the cust_num exists. And if it is just '7' it errors out, but if it is ' 7' it works fine. So I need to somehow add the spaces before it or something.
Ok, we need to back up here. Can you post of DDL and/or describe the table(s) you are inserting into? Can you describe the error? What errors? Are you calliing stored procedure or just inserting directly?It sounds like you might have a foriegn key reference to another table and it already has a Cust_Num that has spaces in front of it..? |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-03 : 01:46:03
|
| Sounds like the record in the cust_num table has been (accidentally?) created with a leading space? |
 |
|
|
|