Results 1 to 4 of 4

Thread: SQL Server BCP

  1. #1
    Join Date
    Dec 2008
    Posts
    3

    Unanswered: SQL Server BCP

    Input File:

    1,abc,xyx
    2,def,mno
    3,ghi,suv

    DB Table Structure:

    Col1 char
    col2 char
    col3 char
    col4 char
    col5 char

    Data in Table after BCP:

    col1 col2 col3 col4 col5

    1 abc xyz ab xy

    2 def mno de mn

    3 ghi suv gh su

    Basically the col4 and col5 are calculated values from col2 and col3 values.

    Does SQL Server BCP utility support such kind of operation? Any pointers will be appreciated.

    Cheers
    GT

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by gtyagi_123
    Basically the col4 and col5 are calculated values from col2 and col3 values.
    Why do you store them at all then?
    Any value that can be calculated should not be stored in the first place

    Any pointers will be appreciated.
    If it's explained somewhere, then most probably in the manual:

    http://msdn.microsoft.com/en-us/libr...2(SQL.90).aspx
    http://msdn.microsoft.com/en-us/libr...9(SQL.90).aspx
    http://msdn.microsoft.com/en-us/libr...3(SQL.90).aspx

    But I don't think it's possible.

    Why don't you import the existing columns, and then "compute" the missing values using an UPDATE statement?

    Or define those columns as computed columns directly, then you don't need to worry about them at all.

  3. #3
    Join Date
    Dec 2008
    Posts
    3
    Hi Shammat

    Thanks for the reply. Even i was thinking in lines of updating the columns but my another concern is performance. I mean will updating or using calculated columns be efficient? Let me also go though the links you suggested.

    Cheers
    GT

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I like the option of a view to calculate our values

    You'd have your base table with three columns, which you BCP into, and then you create a view based on this table which includes the computed values
    Code:
    CREATE VIEW dbo.my_view99
      AS
    SELECT col1
         , col2
         , col3
         , col1 + col2 As [col4]
         , col2 - col3 As [col5]
    FROM   dbo.my_table99
    GO
    
    SELECT *
    FROM   dbo.my_view99
    George
    Home | Blog

Posting Permissions

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