1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Conversion in an INSERT query

Discussion in 'MySQL' started by Germaris, Jan 19, 2013.

  1. #1
    Hi there!

    I need to know how to have automatically the name "BROWN" (example) inserted this way: "Brown".

    The query is a classical and simple query:

    INSERT INTO `list`(`ID`, `lastName`, `firstName`, `school`, `year`) VALUES ([""],[BROWN],[JOHN],[Snowy Mountain],[1985])

    ID is AUTOINCREMENT

    Result should be:

    93, Brown, John, Snowy Mountain, 1985

    I need this tip because I have almost 3000 queries like this to execute and all the names are in caps!!!

    Many thanks in advance for your help!
     
    Solved! View solution.
    Last edited: Jan 19, 2013
    Germaris, Jan 19, 2013 IP
  2. #2
    After insert those queries you can update firstName and lastName column to change the case....

    for lastName column:
    UPDATE school SET lastName = CONCAT(UCASE(LEFT(lastName, 1)), LCASE(SUBSTRING(lastName, 2)));
    for firstName column:
    UPDATE list SET firstName = CONCAT(UCASE(LEFT(firstName, 1)), LCASE(SUBSTRING(firstName, 2)));

    regards

    --amrush
     
    amrush, Jan 20, 2013 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    If you're doing this in a language that has decent string manipulation, you can ProperCase() the data as part of the query:
    $insertString = "INSERT INTO `list`(`lastName`, `firstName`, `school`, `year`) VALUES (ProperCase('BROWN') & "," & ProperCase('JOHN') & ",[Snowy Mountain],[1985])"
    Code (markup):
    The exact syntax would depend on the language.
     
    Rukbat, Jan 20, 2013 IP
  4. Mohit Bumb

    Mohit Bumb Greenhorn

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    strtoupper("bRowN")
    output : BROWN
     
    Mohit Bumb, Jan 20, 2013 IP
  5. Germaris

    Germaris Member

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    Thank you very much, it works nice!
     
    Germaris, Jan 21, 2013 IP