![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| Hi, I have a table, TABLEA ( ROWA[int], ROWB[int] ) and I want to move all the data to another table, TABLEB ( ROWA[int], ROWB[string], ROWC[string] ) ROWC will be a constant string but ROWB will be converted to a string (VARCHAR 255) of the current INT value. How would you move the data from A to B? INSERT INTO TABLEB ( ROWA, ROWB, ROWC ) VALUES ( SELECT ROWA, ROWB FROM TABLEA, 'ROWC'.... ) Not sure how that would work. Thanks FFMG -- 'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory' (http://www.webhostshunter.com/) | 'Recreation Vehicle insurance' (http://www.insurance-owl.com/other/car_rec.php) 'Free URL redirection service' (http://urlkick.com/) ------------------------------------------------------------------------ FFMG's Profile: http://www.httppoint.com/member.php?userid=580 View this thread: http://www.httppoint.com/showthread.php?t=17868 Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing). | |||
|
| Advertisements |
| | #2 | ||
| On 27 Jun, 06:31, FFMG <FFMG.2st...@no-mx.httppoint.com> wrote: > Hi, > > I have a table, TABLEA ( ROWA[int], ROWB[int] ) and I want to move all > the data to another table, TABLEB ( ROWA[int], ROWB[string], > ROWC[string] ) > > ROWC will be a constant string but ROWB will be converted to a string > (VARCHAR 255) of the current INT value. > > How would you move the data from A to B? > > INSERT INTO TABLEB ( > ROWA, > ROWB, > ROWC > ) > VALUES > ( > SELECT ROWA, ROWB FROM TABLEA, > 'ROWC'.... ) > > Not sure how that would work. > > Thanks > > FFMG > > -- > > 'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory' > (http://www.webhostshunter.com/) | 'Recreation Vehicle insurance' > (http://www.insurance-owl.com/other/car_rec.php) > 'Free URL redirection service' (http://urlkick.com/) > ------------------------------------------------------------------------ > FFMG's Profile:http://www.httppoint.com/member.php?userid=580 > View this thread:http://www.httppoint.com/showthread.php?t=17868 > > Message Posted via the webmaster forumhttp://www.httppoint.com, (Ad revenue sharing). I assume you actually mean COLA, COLB, COLC as you are talking about columns and not rows. You also have to use the correct sytax as shown in the manual for INSERT ... SELECT http://dev.mysql.com/doc/refman/5.0/en/insert.html You would write it like this: INSERT INTO TABLEB ( ROWA, ROWB, ROWC ) SELECT ROWA, ROWB, 'ROWC' FROM TABLEA OR more correctly conceptwise: INSERT INTO TABLEB ( COLA, COLB, COLC ) SELECT COLA, COLB, 'COLC' FROM TABLEA | |||
|
| | #3 | ||
| Captain Paralytic;78563 Wrote: > > ... > INSERT INTO TABLEB ( > COLA, > COLB, > COLC > ) > SELECT COLA, COLB, 'COLC' FROM TABLEA Thanks, you are right I was talking about COLA/B/C I just want to make sure that COLB will not be a problem as I am inserting an INT into a VARCHAR(255). I don't need to convert anything? FFMG -- 'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory' (http://www.webhostshunter.com/) | 'Recreation Vehicle insurance' (http://www.insurance-owl.com/other/car_rec.php) 'Free URL redirection service' (http://urlkick.com/) ------------------------------------------------------------------------ FFMG's Profile: http://www.httppoint.com/member.php?userid=580 View this thread: http://www.httppoint.com/showthread.php?t=17868 Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing). | |||
|
| | #4 | ||
| FFMG wrote: > Captain Paralytic;78563 Wrote: >> >> ... >> INSERT INTO TABLEB ( >> COLA, >> COLB, >> COLC >> ) >> SELECT COLA, COLB, 'COLC' FROM TABLEA > > Thanks, you are right I was talking about COLA/B/C > > I just want to make sure that COLB will not be a problem as I am > inserting an INT into a VARCHAR(255). I don't need to convert > anything? > > FFMG I always find the best way to be sure of these things is to knock up test tables and try it out! | |||
|
| | #5 | ||
| Paul Lautman;78676 Wrote: > FFMG wrote: > > Captain Paralytic;78563 Wrote: > >> > >> ... > >> INSERT INTO TABLEB ( > >> COLA, > >> COLB, > >> COLC > >> ) > >> SELECT COLA, COLB, 'COLC' FROM TABLEA > > > > Thanks, you are right I was talking about COLA/B/C > > > > I just want to make sure that COLB will not be a problem as I am > > inserting an INT into a VARCHAR(255). I don't need to convert > > anything? > > > > FFMG > > I always find the best way to be sure of these things is to knock up > test > tables and try it out! Yes, that's what I did, and it does work. But my question was kind of 'best practice'. Because I am sure that moving a float to a string might cause some problems. (Just guessing here). It might work, but is it the right way? FFMG -- 'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory' (http://www.webhostshunter.com/) | 'Recreation Vehicle insurance' (http://www.insurance-owl.com/other/car_rec.php) 'Free URL redirection service' (http://urlkick.com/) ------------------------------------------------------------------------ FFMG's Profile: http://www.httppoint.com/member.php?userid=580 View this thread: http://www.httppoint.com/showthread.php?t=17868 Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing). | |||
|
| | #6 | ||
| On 28 Jun, 06:15, FFMG <FFMG.2sv...@no-mx.httppoint.com> wrote: > Paul Lautman;78676 Wrote: > > > > > > > FFMG wrote: > > > Captain Paralytic;78563 Wrote: > > > >> ... > > >> INSERT INTO TABLEB ( > > >> COLA, > > >> COLB, > > >> COLC > > >> ) > > >> SELECT COLA, COLB, 'COLC' FROM TABLEA > > > > Thanks, you are right I was talking about COLA/B/C > > > > I just want to make sure that COLB will not be a problem as I am > > > inserting an INT into a VARCHAR(255). I don't need to convert > > > anything? > > > > FFMG > > > I always find the best way to be sure of these things is to knock up > > test > > tables and try it out! > > Yes, that's what I did, and it does work. > > But my question was kind of 'best practice'. > > Because I am sure that moving a float to a string might cause some > problems. > (Just guessing here). > > It might work, but is it the right way? > > FFMG > > -- > > 'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory' > (http://www.webhostshunter.com/) | 'Recreation Vehicle insurance' > (http://www.insurance-owl.com/other/car_rec.php) > 'Free URL redirection service' (http://urlkick.com/) > ------------------------------------------------------------------------ > FFMG's Profile:http://www.httppoint.com/member.php?userid=580 > View this thread:http://www.httppoint.com/showthread.php?t=17868 > > Message Posted via the webmaster forumhttp://www.httppoint.com, (Ad revenue sharing).- Hide quoted text - > > - Show quoted text - The "right" way I guess is to use a CAST function and some SQL implementations may require you to do this. MySQL however will handle the casting for you. | |||
|
| Featured Websites | ||||
|
![]() |
| Tags: data, existing, moving, table |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Copying Table Data For Archive | GA | Database | 3 | 07-02-2007 10:58 AM |
| table name as data | Rob Kings | Database | 7 | 07-01-2007 6:27 PM |
| How to take data out of table, restructure the table and then put the data back in | Laphan | Database | 4 | 07-01-2007 6:24 PM |
| Random Script thought By Jon - Gzipped table data | news.cableregina.com | PHP | 0 | 07-01-2007 5:25 PM |
| MP3 player into existing Car Stereo | buffyslay@gmail.com | Car audio | 0 | 06-18-2007 1:40 PM |
| Featured Websites | ||||
|