Results 1 to 6 of 6

Thread: New to SQL

  1. #1
    Join Date
    Nov 2006
    Posts
    3

    Unanswered: New to SQL

    I have a table with a field that is 14 characters long. I have created two more columns with in the same table. I wish to parse each record taking the 14 character field and storing the first 10 characters in one of the newly created fields and take the next 4 characters and store them in the other newly created fields.

    Can someone tell me how to do that?

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Look in BOL (Books Online) at the Left and Right functions.
    Paul

  3. #3
    Join Date
    Nov 2006
    Posts
    3
    I can do the left and right functions. I just don't understand the looping through the records and updating the other fields.

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Run an update query:

    UPDATE TableName
    SET SecondField = Left(FirstField,10),
    ThirdField = Right(FirstField,4)
    Paul

  5. #5
    Join Date
    Nov 2006
    Posts
    3

    Thanks

    Thanks. I was thinking this was going to be more complicated.

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Of course the real question is should you have the other fields in the table, since their values can always be calculated from the first. Generally speaking the answer would be no.
    Paul

Posting Permissions

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