Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-02-2008, 05:05 AM
F Tahbaz
 
Posts: n/a
Default 2 questions

1) How can I insert a column into my table DATA, and make it my
primary key (that will just be a number starting at 1 and increasing n
+1)...

2) I have a column named DATEID in a table DATA that contains the
following format connected to each other(date and name):

20071030Jones
20071020Smith
20070918Rogers
20080122Williams
etc..

What would the syntax be to insert a column to the right of this one,
and extract the first 8 digits from the data in the DATEID column and
insert that into the new column DATE, therefore making it easier for
me to query against an actual date?

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-02-2008, 05:05 AM
ThanksButNo
 
Posts: n/a
Default Re: 2 questions

On Apr 30, 3:59 pm, F Tahbaz <ftah...@gmail.com> wrote:
> 1) How can I insert a column into my table DATA, and make it my
> primary key (that will just be a number starting at 1 and increasing n
> +1)...
>
> 2) I have a column named DATEID in a table DATA that contains the
> following format connected to each other(date and name):
>
> 20071030Jones
> 20071020Smith
> 20070918Rogers
> 20080122Williams
> etc..
>
> What would the syntax be to insert a column to the right of this one,
> and extract the first 8 digits from the data in the DATEID column and
> insert that into the new column DATE, therefore making it easier for
> me to query against an actual date?
>
> Thanks


You need something to parse your input, such as Python, PHP, C/C++,
Java, Perl, etc.

That isn't something MySQL does, or any other database for that matter.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-02-2008, 05:05 AM
Rik Wasmus
 
Posts: n/a
Default Re: 2 questions

On Thu, 01 May 2008 00:59:59 +0200, F Tahbaz <ftahbaz@gmail.com> wrote:

> 1) How can I insert a column into my table DATA, and make it my
> primary key (that will just be a number starting at 1 and increasing n
> +1)...


ALTER TABLE data ADD COLUMN id int PRIMARY KEY AUTO_INCREMENT FIRST;

> 2) I have a column named DATEID in a table DATA that contains the
> following format connected to each other(date and name):
>
> 20071030Jones
> 20071020Smith
> 20070918Rogers
> 20080122Williams
> etc..
>
> What would the syntax be to insert a column to the right of this one,
> and extract the first 8 digits from the data in the DATEID column and
> insert that into the new column DATE, therefore making it easier for
> me to query against an actual date?


IF the DATEID column is reliable:
UPDATE TABLE data ADD COLUMN datefld DATE NOT NULL AFTER dateid;
ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,9);
--
Rik Wasmus
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-02-2008, 05:05 AM
Rik Wasmus
 
Posts: n/a
Default Re: 2 questions

On Thu, 01 May 2008 08:47:42 +0200, Rik Wasmus
<luiheidsgoeroe@hotmail.com> wrote:
> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,9);


Ofcourse:
ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,8));
--
Rik Wasmus
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-02-2008, 05:05 AM
Luuk
 
Posts: n/a
Default Re: 2 questions

Rik Wasmus schreef:
> On Thu, 01 May 2008 08:47:42 +0200, Rik Wasmus
> <luiheidsgoeroe@hotmail.com> wrote:
>> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,9);

>
> Ofcourse:
> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,8));


Of course:
ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,1,8));

<docs http://tinyurl.com/7e7ve>
For all forms of SUBSTRING(), the position of the first character in the
string from which the substring is to be extracted is reckoned as 1.
</docs>
--
Luuk
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-02-2008, 05:05 AM
Rik Wasmus
 
Posts: n/a
Default Re: 2 questions

On Thu, 01 May 2008 10:44:36 +0200, Luuk <Luuk@invalid.lan> wrote:

> Rik Wasmus schreef:
>> On Thu, 01 May 2008 08:47:42 +0200, Rik Wasmus
>> <luiheidsgoeroe@hotmail.com> wrote:
>>> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,9);

>> Ofcourse:
>> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,8));

>
> Of course:
> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,1,8));
>
> <docs http://tinyurl.com/7e7ve>
> For all forms of SUBSTRING(), the position of the first character in the
> string from which the substring is to be extracted is reckoned as 1.
> </docs>


D'oh!

.... I really hate 1-indexed anything..... Totally throws me off balance.
--
Rik Wasmus
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-02-2008, 05:05 AM
Captain Paralytic
 
Posts: n/a
Default Re: 2 questions

On 1 May, 07:03, ThanksButNo <no.no.tha...@gmail.com> wrote:
> On Apr 30, 3:59 pm, F Tahbaz <ftah...@gmail.com> wrote:
>
>
>
> > 1) How can I insert a column into my table DATA, and make it my
> > primary key (that will just be a number starting at 1 and increasing n
> > +1)...

>
> > 2) I have a column named DATEID in a table DATA that contains the
> > following format connected to each other(date and name):

>
> > 20071030Jones
> > 20071020Smith
> > 20070918Rogers
> > 20080122Williams
> > etc..

>
> > What would the syntax be to insert a column to the right of this one,
> > and extract the first 8 digits from the data in the DATEID column and
> > insert that into the new column DATE, therefore making it easier for
> > me to query against an actual date?

>
> > Thanks

>
> You need something to parse your input, such as Python, PHP, C/C++,
> Java, Perl, etc.
>
> That isn't something MySQL does, or any other database for that matter.


I think you need to study the manual before making claims like this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-02-2008, 05:05 AM
ThanksButNo
 
Posts: n/a
Default Re: 2 questions

On May 1, 2:04 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 1 May, 07:03, ThanksButNo <no.no.tha...@gmail.com> wrote:
>
>
>
> > On Apr 30, 3:59 pm, F Tahbaz <ftah...@gmail.com> wrote:

>
> > > 1) How can I insert a column into my table DATA, and make it my
> > > primary key (that will just be a number starting at 1 and increasing n
> > > +1)...

>
> > > 2) I have a column named DATEID in a table DATA that contains the
> > > following format connected to each other(date and name):

>
> > > 20071030Jones
> > > 20071020Smith
> > > 20070918Rogers
> > > 20080122Williams
> > > etc..

>
> > > What would the syntax be to insert a column to the right of this one,
> > > and extract the first 8 digits from the data in the DATEID column and
> > > insert that into the new column DATE, therefore making it easier for
> > > me to query against an actual date?

>
> > > Thanks

>
> > You need something to parse your input, such as Python, PHP, C/C++,
> > Java, Perl, etc.

>
> > That isn't something MySQL does, or any other database for that matter.

>
> I think you need to study the manual before making claims like this.


D'OH!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 05-02-2008, 05:05 AM
Mark A. Boyd
 
Posts: n/a
Default Re: 2 questions

Luuk <Luuk@invalid.lan> posted in comp.databases.mysql:

> Rik Wasmus schreef:
>> On Thu, 01 May 2008 08:47:42 +0200, Rik Wasmus
>> <luiheidsgoeroe@hotmail.com> wrote:
>>> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,9);

>>
>> Ofcourse:
>> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,8));

>
> Of course:
> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,1,8));


Of course:
UPDATE data SET datefld = DATE(SUBSTRING(dateid,1,8));



--
Mark A. Boyd
Keep-On-Learnin'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 05-05-2008, 05:51 AM
Rik Wasmus
 
Posts: n/a
Default Re: 2 questions

Mark A. Boyd wrote:
> Luuk <Luuk@invalid.lan> posted in comp.databases.mysql:
>
>> Rik Wasmus schreef:
>>> On Thu, 01 May 2008 08:47:42 +0200, Rik Wasmus
>>> <luiheidsgoeroe@hotmail.com> wrote:
>>>> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,9);
>>> Ofcourse:
>>> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,8));

>> Of course:
>> ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,1,8));

>
> Of course:
> UPDATE data SET datefld = DATE(SUBSTRING(dateid,1,8));


Hehe, took me a while to see the difference, damned US international
keyboard....

Of course, it doesn't help that for the past 2 days here in Holland
we've had one national holiday after the next...
--
Rik Wasmus
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

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



All times are GMT. The time now is 05:08 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145