Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Posts
    176

    Unanswered: Breaking column data

    DBA's

    How do I break a column data into 2 or more columns.

    Example, I have a 7 character column that I want to break into 3 columns of 3,2 and 2 character respectively. Let me know how the query would look like.

    Thanks

  2. #2
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    You could use left(), substring() functions:

    select left(column,2), substring(column,3,2),....

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Don't forget RIGHT

    Code:
    USE Northwind
    GO
    CREATE TABLE myTable99 (Col1 char(7))
    GO
    
    INSERT INTO myTable99(Col1)
    SELECT '1234567' UNION ALL
    SELECT 'abcdefg' UNION ALL
    SELECT 'qwertyu' UNION ALL
    SELECT 'lkjhgfd' UNION ALL
    SELECT '1212312'
    
    SELECT	  LEFT(Col1,2) 		AS [Left]
    	, SUBSTRING(Col1,3,3)   AS Center
    	, RIGHT(Col1,2) 	AS [Right]
      FROM	  myTable99
    GO
    
    DROP TABLE myTable99
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    Don't forget about your bol - check out string functions.

Posting Permissions

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