SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Insert into and select table

    Hello everyone, I hope your help.

    I need insert into _tbl_2 the values of _tbl_1 for Db MySql.

    _tbl_1:
    Code:
    CTS	Events
    DDDS	12345
    EEES	123456
    FFFS	78901

    I need this output in _tbl2:
    Code:
    ID	_CTS	Events
    1	DDDS	DDD 012345
    2	EEES	EEE 123456
    3	FFFS	FFF 078901
    I need compose this string for the field Events:
    Code:
    DDD 012345
    EEE 123456
    FFF 078901
    If the events value is a five numbers I need insert 0 value first number:
    Code:
    DDD 12345 ===> DDD 012345
    EEE 123456 ===> EEE 123456
    FFF 78901 ===> FFF 078901
    I try this query:

    Code:
    insert into _tbl_2
    (
     `ID`, 
     `_CTS`, 
     `Events`
    )
    (
    select 
      0,
     `CTS`,
      LEFT(CTS,3) & "0"
      from _tbl_1
    )
    Buit in the field `Events` is inserted only 0 value...

    Can someone help me?
    Thanks in advance.

    Chevy

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Code:
    INSERT 
      INTO _tbl_2
         ( ID
         , _CTS
         , Events )
    SELECT 0
         , CTS
         , CONCAT(LEFT(CTS,3)
                 ,' '
                 ,RIGHT(CONCAT('0',Events),6))
      FROM _tbl_1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    Code:
    INSERT 
      INTO _tbl_2
         ( ID
         , _CTS
         , Events )
    SELECT 0
         , CTS
         , CONCAT(LEFT(CTS,3)
                 ,' '
                 ,RIGHT(CONCAT('0',Events),6))
      FROM _tbl_1

    I'd appreciate your help so very much.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •