Sum or aggregate operation......

  • Hi All

    I have the following:

    I have a table that gets populated with a .csv file that get imported every day... the table columns are defined as varchar, because when I do the import it doesnt like any other datatype, eg. date column(datetime)

    When I run my query I get the following error:

    Error converting data type varchar to float....

    When I changed it to varbinary, I got the following error:

    Sum or aggregate function operation cannot take a varbinary data type as an argument...

    The query is as follows:

    Select sum(cast(F9 as varbinary(8)))

    from Table

    What Am I doing wrong?? 

    Thanks

    Anchelin

  • How are you importing the CSV file?

    Almost always let SQL Server to decide how to convert data. You don't have to do it in most cases...

     


    N 56°04'39.16"
    E 12°55'05.25"

  • I created the table, right click on table, all tasks, import, and followed the steps....

  • Please post some rows of source data, the CSV file.

    Also provide DDL for target table.

     


    N 56°04'39.16"
    E 12°55'05.25"

  • Hi

    the rows:

    CTSAPP01.engenoil.netBuffer%rcache2-Feb-07Buffer->%rcache100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100100
    CTSAPP01.engenoil.netBuffer%wcache2-Feb-07Buffer->%wcache383856453839403856483837373754513737373752543738394252543639424150553843374349584239434447574043404248594542363845623738373845634237373844653938373843663738363842673738373940683838
    CTSAPP01.engenoil.netBufferbread/s2-Feb-07Buffer->bread/s1001000010000100010002000001010011101001000131213000010020100000010120021100000120000000000
    CTSAPP01.engenoil.netBufferbwrit/s2-Feb-07Buffer->bwrit/s74717573738576627470706767717374756965727776686678111731207580105898311781109701188010298811141227912891121881171081111431217576779376797776788510570767678858074727375837174767775857665687171847268
    CTSAPP01.engenoil.netBufferlread/s2-Feb-07Buffer->lread/s9042962125790130819524957298661036325318153089564981997099668236921743595509584998192052243919859959698519742928222117216259545926394919540206442389192789563945193471892926094905991198998894518064281619126891691018940170883053089018997909194361656932387926691489097899616231340709325945195599179150263641292829082967194811408238818974092219365921212832412669342992899139470118084395296099777
    CTSAPP01.engenoil.netBufferlwrit/s2-Feb-07Buffer->lwrit/s119114171133117140127100166134112107107114160151119111104115163163108106128193153260117131182151165262132190111208157242167133199219149300151212146202208272258210119122141243121127123122143231180112121123140240130119114118130247113119120124128257121106108116118264117110
    CTSAPP01.engenoil.netBufferpread/s2-Feb-07Buffer->pread/s000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    CTSAPP01.engenoil.netBufferpwrit/s2-Feb-07Buffer->pwrit/s000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

     

    DDL:

    create table TAB(

    col1 (varchar) 8000 collate Latin1_General_CI_AS Null,

    col2(varchar) 8000 collate Latin1_General_CI_AS Null,

    col3  (varchar) 8000 collate Latin1_General_CI_AS Null,

    up to 256 cols

     

    Thanks....

     

  • You are trying to import all those records into three columns?

     


    N 56°04'39.16"
    E 12°55'05.25"

  • Hi

    No... I created a table with 256 columns, the same as CSV file...

  • You will get errors if you create 256 column of width 8000.

    For the last 200 columns or so, don't use VARCHAR. Use INT since all values are integer anyway.

    And the first 4 column you create as VARCHAR(100).

    Use a value that is the largest length possible for each one one of the first 4 columns individually.


    N 56°04'39.16"
    E 12°55'05.25"

  • So... make my first five columns varchar and my other columns???

    Also what length should I give my columns?

    Thanks for your help so far!

    Anchelin

  • I did exectly as you said and when I did the import gave me an error:

    TransformCopy 'DirectCopyXform' conversion error: Conversion invalid for datatypes on column pair6 (source column 'Col006'(DBTYPE_STR) destination column 'F6' (DBTYPE_I4)

    the first 4 columns varchar(255), rest of the columns int....

    Thanks

    Anchelin

  • Are there empty strings somewhere in those numeric columns?

    Empty string cannot be converted to int. You must use NULLIF(COL_STR, '') to make it NULL.

    Check data in the file. There must be non-numeric values somewhere.

    _____________
    Code for TallyGenerator

  • What is the delimiter for the csv file (hard to tell from the post)

    The data you posted is formatted as 6 char columns (although one maybe date) before the numbers, this is consistent with the error

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply