Bluehost.com Web Hosting $6.95

leading zero removed from varchar(6)

This is a discussion on leading zero removed from varchar(6) within the MySQL Database forums, part of the Database Forums category; Hi I have a table where a field is described as checkin_time varchar(6). The value might have a leading ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-29-2006
John
 
Posts: n/a
Default leading zero removed from varchar(6)

Hi

I have a table where a field is described as checkin_time varchar(6). The
value might have a leading zero (0730) . When I SELECT checkin_time the
leading zero disappears. Any ideas why?

Regards
John


Reply With Quote
  #2 (permalink)  
Old 10-29-2006
Radoulov, Dimitre
 
Posts: n/a
Default Re: leading zero removed from varchar(6)


> I have a table where a field is described as checkin_time varchar(6). The
> value might have a leading zero (0730) . When I SELECT checkin_time the
> leading zero disappears. Any ideas why?


You have to use quotes for strings (single or double, dipends on you
sql_mode setting):

mysql> create table t(a varchar(6));
Query OK, 0 rows affected (0.12 sec)

mysql> insert into t values (0730);
Query OK, 1 row affected (0.05 sec)

mysql> insert into t values ('0730');
Query OK, 1 row affected (0.04 sec)

mysql> select * from t;
+------+
| a |
+------+
| 730 |
| 0730 |
+------+
2 rows in set (0.00 sec)

mysql> select @@sql_mode;
+----------------------------------------------------------------+
| @@sql_mode |
+----------------------------------------------------------------+
| STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_ SUBSTITUTION |
+----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> insert into t values ("0730");
Query OK, 1 row affected (0.37 sec)

mysql> set sql_mode=ANSI_QUOTES;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values ("0730");
ERROR 1054 (42S22): Unknown column '0730' in 'field list'


Regards
Dimitre


Reply With Quote
  #3 (permalink)  
Old 10-29-2006
Jerry Stuckle
 
Posts: n/a
Default Re: leading zero removed from varchar(6)

John wrote:
> Hi
>
> I have a table where a field is described as checkin_time varchar(6). The
> value might have a leading zero (0730) . When I SELECT checkin_time the
> leading zero disappears. Any ideas why?
>
> Regards
> John
>
>


John,

It the leading zero disappearing when you select the time, or when you
display it? What language are you using? And what's your code?

Languages which don't have strong typing may take this as a numeric
value and drop leading zeros.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #4 (permalink)  
Old 10-29-2006
John
 
Posts: n/a
Default Re: leading zero removed from varchar(6)

Hi folks

OK, I am using Perl, where $x can be any type of variable (string numeric
etc)
I need to recheck that there are quotes surrounding the "0745".
Will be back.

Regards
John


Reply With Quote
  #5 (permalink)  
Old 10-29-2006
Brian Wakem
 
Posts: n/a
Default Re: leading zero removed from varchar(6)

John wrote:

> Hi folks
>
> OK, I am using Perl, where $x can be any type of variable (string numeric
> etc)
> I need to recheck that there are quotes surrounding the "0745".
> Will be back.
>
> Regards
> John



In Perl, if $x contain "0745" and you do any thing numerical with $x, it
will become 745.

$ perl -e '$x = "0745";print $x,"\n"'
0745
$ perl -e '$x = "0745";$x+=0;print $x,"\n"'
745


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
Reply With Quote
  #6 (permalink)  
Old 10-30-2006
Daz
 
Posts: n/a
Default Re: leading zero removed from varchar(6)


Brian Wakem wrote:
> John wrote:
>
> > Hi folks
> >
> > OK, I am using Perl, where $x can be any type of variable (string numeric
> > etc)
> > I need to recheck that there are quotes surrounding the "0745".
> > Will be back.
> >
> > Regards
> > John

>
>
> In Perl, if $x contain "0745" and you do any thing numerical with $x, it
> will become 745.
>
> $ perl -e '$x = "0745";print $x,"\n"'
> 0745
> $ perl -e '$x = "0745";$x+=0;print $x,"\n"'
> 745


I am just taking a stab in the dark here, but would it make any
difference using single quotes and not double quotes?

Reply With Quote
  #7 (permalink)  
Old 10-30-2006
Brian Wakem
 
Posts: n/a
Default Re: leading zero removed from varchar(6)

Daz wrote:

>
> Brian Wakem wrote:
>> John wrote:
>>
>> > Hi folks
>> >
>> > OK, I am using Perl, where $x can be any type of variable (string
>> > numeric etc)
>> > I need to recheck that there are quotes surrounding the "0745".
>> > Will be back.
>> >
>> > Regards
>> > John

>>
>>
>> In Perl, if $x contain "0745" and you do any thing numerical with $x, it
>> will become 745.
>>
>> $ perl -e '$x = "0745";print $x,"\n"'
>> 0745
>> $ perl -e '$x = "0745";$x+=0;print $x,"\n"'
>> 745

>
> I am just taking a stab in the dark here, but would it make any
> difference using single quotes and not double quotes?



No.


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:19 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0