Bulk Insert Errant File

Hello Again,
It's been a troublesome day. I'm trying to import a file with the normal manual import process. Import formats and maps are good. The issue is file system provisioning and behavior I've not seen before.
The location is using Bulk Insert.
When the xxxxxxxxxxxx.tmp file is created, it is being created in C:\Document and Settings\AdminUserID\LOCALSETTINGS\Temp.
One would first think that the application was created with an app path that does not conform to UNC. It does. \\servername\AppFolders\ApplicationX
Why would it choose this location to create the temp file? Usually the .tmp file is created right inside the inbox...
Very confused, appreciate the help.
-Richard

We have an ORACLE DB.
In the past I have seen where the Database service/user doesn't have permissions to the file system and that will create an error.
However, even in those situations the Bulk Insert *.tmp file is created in the application's Inbox. This is completely different as the .tmp file is being created in the System Admin user's Document and Settings folder. I don't even know where it is getting a reference to this folder.

Similar Messages

  • Bulk Insert CSV file in Oracle 9i

    Greetings all,
    Is there a similar way in Oracle to the Bulk Insert Command in SQL Server to bulk load a csv file in Oracle?
    Something else then the External Table and the SQL*Loader.
    Sincerely
    Dan

    Here is an example:
    CREATE TABLE EXT_ASSC
       (     LEVEL_1 VARCHAR2(30),
         LEVEL_2 VARCHAR2(50),
         CATEGORY_CODE VARCHAR2(100),
         LEVEL_3 VARCHAR2(100)
       ORGANIZATION EXTERNAL
        ( TYPE ORACLE_LOADER
          DEFAULT DIRECTORY some_directory
          ACCESS PARAMETERS
          ( RECORDS DELIMITED BY NEWLINE
              NODISCARDFILE
              NOLOGFILE
              BADFILE 'my_bad_file.bad'
            FIELDS
              TERMINATED BY ','
              LRTRIM
              MISSING FIELD VALUES ARE NULL
          LOCATION
           ( 'some_file.csv'
       REJECT LIMIT UNLIMITED;

  • SQL Server 2012 Express bulk Insert flat file 1million rows with "" as delimeter

    Hi,
    I wanted to see if anyone can help me out. I am on SQL server 2012 express. I cannot use OPENROWSET because my system is x64 and my Microsoft office suit is x32 (Microsoft.Jet.OLEDB.4.0).
    So I used Import wizard and is not working either. 
    The only thing that let me import this large file, is:
    CREATE TABLE #LOADLARGEFLATFILE
    Column1
    varchar(100), Column2 varchar(100), Column3 varchar(100),
    Column4 nvarchar(max)
    BULK INSERT
    #LOADLARGEFLATFILE
    FROM 'C:\FolderBigFile\LARGEFLATFILE.txt'
    WITH 
    FIRSTROW = 2,
    FIELDTERMINATOR ='\t',
    ROWTERMINATOR ='\n'
    The problem with CREATE TABLE and BULK INSERT is that my flat file comes with text qualifiers - "". Is there a way to prevent the quotes "" from loading in the bulk insert? Below is the data. 
    Column1
    Column2
    Column3
    Column4
    "Socket Adapter"
    8456AB
    $4.25
    "Item - Square Drive Socket Adapter | For "
    "Butt Splice" 
    9586CB
    $14.51
    "Item - Butt Splice"
    "Bleach"
    6589TE
    $27.30
    "Item - Bleach | Size - 96 oz. | Container Type"
    Ed,
    Edwin Lopera

    Hi lgnusLumen,
    According to your description, you use BULK INSERT to import data from a data file to the SQL table. However, to be usable as a data file for bulk import, a CSV file must comply with the following restrictions:
    1. Data fields never contain the field terminator.
    2. Either none or all of the values in a data field are enclosed in quotation marks ("").
    In your data file, the quotes aren't consistent, if you want to prevent the quotes "" from loading in the bulk insert, I recommend you use SQL Server Import and Export Wizard tools in SQL Server Express version. area, it will allow to strip the
    double quote from columns, you can review the following screenshot.
    In other SQL Server version, we can use SQL Server Integration Services (SSIS) to import data from a flat file (.csv) with removing the double quotes. For more information, you can review the following article.
    http://www.mssqltips.com/sqlservertip/1316/strip-double-quotes-from-an-import-file-in-integration-services-ssis/
    In addition, you can create a function to convert a CSV to a usable format for Bulk Insert. It will replace all field-delimiting commas with a new delimiter. You can then use the new field delimiter instead of a comma. For more information, see:
    http://stackoverflow.com/questions/782353/sql-server-bulk-insert-of-csv-file-with-inconsistent-quotes
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Bulk insert into a table

    What is the counter part for sql server BULK insert in Oracle.
    I have gone through an existing thread for the same question Bulk Insert CSV file in Oracle 9i But here it is suggested to read from a file into and external table and then to create my own table reading from external table.
    But I want to read directly from a file to an existing table in my database. How do I achieve this?
    Thank you,
    Praveen.

    Refer to
    http://download.oracle.com/docs/cd/B14117_01/server.101/b10825/ldr_modes.htm#i1008078
    "During Direct Path load through SQL Loader, some constaints and all db triggers are disabled. With the conventional path load method, arrays of rows are inserted with standard SQL INSERT statements—integrity constraints and insert triggers are automatically applied.
    After the rows are loaded and indexes rebuilt, any triggers that were disabled are automatically reenabled. The log file lists all triggers that were disabled for the load. There should not be any errors reenabling triggers."

  • How to get current month from filename and bulk insert from text file into table?

    I set up some dynamic SQL to help my bulk copy data from a text file to a table.  This works fine for files that come in every day; I get the previous day’s data, based on the file name that’s placed
    in the folder.  That’s why I’m using the ‘-1’.  The dates will look like this: '20140131', so I'm using type 112.
    declare @fullpath1 varchar(1000)
    select @fullpath1 = '''\\system.local\ms\london\FTP\' + convert(varchar, getdate()-1, 112) + '_INDEXPRICES_EOM.SPC'''
    declare @cmd1 nvarchar(1000)
    print (@cmd1)
    select @cmd1 = 'bulk insert [dbo].[SB_Monthly] from ' + @fullpath1 + ' with (FIELDTERMINATOR = ''\t'', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR=''0x0a'')'
    print(@cmd1)
    exec (@cmd1)
    I think the syntax will be somewhat similar to this:
    YEAR(date_column)=YEAR(getdate()) AND MONTH(date_column)=MONTH(getdate())
    I’m not totally sure how to incorporate that into my current syntax.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    I tried a couple versions of this.
    Declare @StartDate Date, @EndDate Date
    Select @StartDate = convert(varchar, getdate()-28, 112), @EndDate = convert(varchar, getdate()-1, 112)
    BEGIN
    declare @fullpath1 varchar(1000)
    select @fullpath1 = '''\\ms\london\FTP\' + ''' between ''' + Convert(Varchar(10), @StartDate, 101) + ''' and ''' + Convert(Varchar(10), @EndDate, 101) + '''_SP.SPC'''
    declare @cmd1 nvarchar(1000)
    print (@cmd1)
    select @cmd1 = 'bulk insert [dbo].[SPBMI_Monthly] from ' + @fullpath1 + ' with (FIELDTERMINATOR = ''\t'', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR=''0x0a'')'
    print(@cmd1)
    exec (@cmd1)
    END
    Here’s the string:
    bulk insert [dbo].[SPBMI_Monthly] from '\\ms\london\FTP\' between '02/03/2014' and '03/02/2014'_SP.SPC' with (FIELDTERMINATOR = '\t', FIRSTROW = 5, LASTROW = 675, ROWTERMINATOR='0x0a')
    The error message I keep getting is:
    Msg 156, Level 15, State 1, Line 1
    Incorrect syntax near the keyword 'between'.
    Msg 319, Level 15, State 1, Line 1
    Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
    I feel like I’m already pushing this thing to the limit. 
    Maybe this last part isn’t possible.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • Bulk Insert into a Table from CSV file

    I have a CSV file with 1000 records and i have to insert those records into a table.
    I tried for Bulk Insert command and Load data infile command but it throws error.
    Am using Oracle 10g Express Edition.
    I want to achieve it thru query command and not by plsql procedures
    Please send me query syntax for this problem. . . .
    Thanks in Advance,
    Hariharan ST.

    Hi
    If you create an external table that points to your csv file you will then be able populate your table from a query.
    See: http://www.astral-consultancy.co.uk/cgi-bin/hunbug/doco.cgi?11210
    Hope this helps

  • BULK INSERT from a text (.csv) file - read only specific columns.

    I am using Microsoft SQL 2005, I need to do a BULK INSERT from a .csv I just downloaded from paypal.  I can't edit some of the columns that are given in the report.  I am trying to load specific columns from the file.
    bulk insert Orders
    FROM 'C:\Users\*******\Desktop\DownloadURL123.csv'
       WITH
                  FIELDTERMINATOR = ',',
                    FIRSTROW = 2,
                    ROWTERMINATOR = '\n'
    So where would I state what column names (from row #1 on the .csv file) would be used into what specific column in the table.
    I saw this on one of the sites which seemed to guide me towards the answer, but I failed.. here you go, it might help you:
    FORMATFILE [ = 'format_file_path' ]
    Specifies the full path of a format file. A format file describes the data file that contains stored responses created using the bcp utility on the same table or view. The format file should be used in cases in which:
    The data file contains greater or fewer columns than the table or view.
    The columns are in a different order.
    The column delimiters vary.
    There are other changes in the data format. Format files are usually created by using the bcp utility and modified with a text editor as needed. For more information, see bcp Utility.

    Date, Time, Time Zone, Name, Type, Status, Currency, Gross, Fee, Net, From Email Address, To Email Address, Transaction ID, Item Title, Item ID, Buyer ID, Item URL, Closing Date, Reference Txn ID, Receipt ID,
    "04/22/07", "12:00:21", "PDT", "Test", "Payment Received", "Cleared", "USD", "321", "2.32", "3213', "[email protected]", "[email protected]", "", "testing", "392302", "jdal32", "http://ddd.com", "04/22/03", "", "",
    "04/22/07", "12:00:21", "PDT", "Test", "Payment Received", "Cleared", "USD", "321", "2.32", "3213', "[email protected]", "[email protected]", "", "testing", "392932930302", "jejsl32", "http://ddd.com", "04/22/03", "", "",
    Do you need more than 2 rows? I did not include all the columns from the actual csv file but most of it, I am planning on taking to the first table these specfic columns: date, to email address, transaction ID, item title, item ID, buyer ID, item URL.
    The other table, I don't have any values from here because I did not list them, but if you do this for me I could probably figure the other table out.
    Thank you very much.

  • Bulk Insert Task Cannot bulk load because the file could not be opened.operating system error error code 3(The system cannot find the path specified.)

    Following error i am getting after i chnaged the Path in Config File from
    \\vs01\d$\\Deployment\Files\temp.txt
    to
    C:\Deployment\Files\temp.txt
    [Bulk Insert Task] Error: An error occurred with the following error message: "Cannot bulk load because the file "C:\Deployment\Files\temp.txt" could not be opened. Operating system error code 3(The system cannot find the path specified.).". 

    I think i know whats going on. The Bulk Insert task runs by executing sql command (bulk insert) internally from the target sql server to load the file. This means that the SQL Server Agent of the target sql server should have permissions on the file you trying to load. This also means that you need to use UNC path instead to specify the file path (if the target server in on different machine)
    Also from BOL (see section Usage Considerations - last bullet point)
    http://msdn.microsoft.com/en-us/library/ms141239.aspx
    * Only members of the sysadmin fixed server role can run a package that contains a Bulk Insert task.
    Make sure you take care of this as well.
    HTH
    ~Mukti
    Mukti

  • Bulk insert of text file Help PLEASE!

    Hello,
    I am trying to insert the following data into a sql server table.
    11470012 31020141100AMFI2              TENTATIVE APPOINTMENT SET FOR 03/17/2014 AT 10:00 AM
    11470012 31720141000AMFI7              INTERVIEW COMPLETED.
    I am using the following code.
    Bulk Insert dbo.Totalnt
    From 'c:\totalnt.txt'
    with (rowterminator = '\n');
    I get the following error.
    Msg 4866, Level 16, State 7, Line 4
    The bulk load failed. The column is too long in the data file for row 1, column 1. Verify that the field terminator and row terminator are specified correctly.
    Msg 7399, Level 16, State 1, Line 4
    The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
    Msg 7330, Level 16, State 2, Line 4
    Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
    Please help,
    M. Wilson
    M. Wilson

    Here is the create table statement.  I appreciate your assistance.  I have never imported a file into sql server.
    USE
    [2013ProductionData]
    GO
    /****** Object:  Table [dbo].[Totalnt]    Script Date: 03/31/2014 21:24:17 ******/
    SET
    ANSI_NULLS
    ON
    GO
    SET
    QUOTED_IDENTIFIER
    ON
    GO
    CREATE
    TABLE [dbo].[Totalnt](
    [Cluster] [nvarchar]
    (2)
    NOT
    NULL,
    [Project] [nvarchar]
    (3)
    NOT
    NULL,
    [Case] [nvarchar]
    (2)
    NOT
    NULL,
    [RecType] [nvarchar]
    (1)
    NULL,
    [ContactDateM] [nvarchar]
    (2)
    NULL,
    [ContactDateD] [nvarchar]
    (2)
    NULL,
     [ContactDateY] [nvarchar]
    (4)
    NULL,
    [ContactTimeH] [nvarchar]
    (2)
    NULL,
    [ContactTimeM] [nvarchar]
    (2)
    NULL,
    [ContactTimeAMPM] [nvarchar]
    (2)
    NULL,
    [Who] [nvarchar]
    (2)
    NULL,
    [Result] [nvarchar]
    (1)
    NULL,
    [ApptDateM] [nvarchar]
    (2)
    NULL,
    [ApptDateD] [nvarchar]
    (2)
    NULL,
    [ApptDateY] [nvarchar]
    (4)
    NULL,
    [ApptTimeH] [nvarchar]
    (2)
    NULL,
    [ApptTimeM] [nvarchar]
    (2)
    NULL,
    [ApptTimeAMPM] [nvarchar]
    (2)
    NULL,
    [Comments1] [nvarchar]
    (50)
    NULL,
    [Comments2] [nvarchar]
    (50)
    NULL,
    [Comments3] [nvarchar]
    (50)
    NULL,
    [Comments4] [nvarchar]
    (50)
    NULL
    ON [PRIMARY]
    GO
    M. Wilson

  • Bulk Insert Failure: Unexpected end of file

    Hi all,
    I have a Bulk Insert task which pulls data from a .csv file to SQL server table.
    It works fine 99 out of 100 times, but sometimes it throws the following error in production.
    "System exception: An error occurred with the following error message: "Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information
    about the error.Bulk load: An unexpected end of file was encountered in the data file.".  "
    My Client says that there was no change to the file and it runs fine the next time.Its a error which I could not reproduce in development.
    I have an interface prior to this bulk insert interface to check whether the file is completely available(i.e i try to open the file and check whether its used by any other process).
    I'm supposed to give an answer for why it fails sometimes. Your thoughts on this?
    Rajkumar

    The Bulk insert task is used in SSIS package. The error Posted in my first post is what I got from SSIS..
    Why don't you use Data Flow task? BULK INSERT is fast, but not much error control.
    BOL quote ( http://msdn.microsoft.com/en-us/library/ms141679.aspx ) : "Error Handling in Data
    When a data flow component applies a transformation to column data, extracts data from sources, or loads data into destinations, errors can occur. Errors frequently occur because of unexpected data values. For example, a data conversion fails because a column
    contains a string instead of a number, an insertion into a database column fails because the data is a date and the column has a numeric data type, or an expression fails to evaluate because a column value is zero, resulting in a mathematical operation that
    is not valid.
    Errors typically fall into one the following categories:
    Data conversion errors, which occur if a conversion results in loss of significant digits, the loss of insignificant digits, and the truncation of strings. Data conversion errors also occur if the requested conversion is not supported.
    Expression evaluation errors, which occur if expressions that are evaluated at run time perform invalid operations or become syntactically incorrect because of missing or incorrect data values.
    Lookup errors, which occur if a lookup operation fails to locate a match in the lookup table.
    Many data flow components support error outputs, which let you control how the component handles row-level errors in both incoming and outgoing data. You specify how the component behaves when truncation or an error occurs by setting options on individual
    columns in the input or output. For example, you can specify that the component should fail if customer name data is truncated, but ignore errors on another column that contains less important data."
    http://msdn.microsoft.com/en-us/library/ms141679.aspx
    Kalman Toth SQL SERVER & BI TRAINING

  • First Row Record is not inserted from CSV file while bulk insert in sql server

    Hi Everyone,
    I have a csv file that needs to be inserted in sql server. The csv file will be format will be like below.
    1,Mr,"x,y",4
    2,Mr,"a,b",5
    3,Ms,"v,b",6
    While Bulk insert it coniders the 2nd column as two values (comma separte) and makes two entries .So i used filelterminator.xml.  
    Now, the fields are entered into the column correctly. But now the problem is, the first row of the csv file is not reading in sql server. when i removed the  terminator,  i can get the all records. But i must use the above code terminator. If
    am using means, am not getting the first row record.
    Please suggests me some solution.
    Thanks,
    Selvam

    Hi,
    I have a csv file (comma(,) delimited) like this which is to be insert to sql server. The format of the file when open in notepad like below:
    Id,FirstName,LastName,FullName,Gender
    1,xx,yy,"xx,yy",M
    2,zz,cc,"zz,cc",F
    3,aa,vv,"aa,vv",F
    The below is the bulk insert query which is used for insert above records,
    EXEC(BULK INSERT EmployeeData FROM '''+@FilePath+'''WITH
    (formatfile=''d:\FieldTerminator.xml'',
    ROWTERMINATOR=''\n'',
    FIRSTROW=2)'
    Here, I have used format file for the "Fullname" which has comma(,) within the field. The format file is:
    The problem is , it skip the first record (1,xx,yy,"xx,yy",M) when i use the format file. When i remove the format file from the query, it takes all the records but the "fullName" field makes the problem because of comma(,) within the
    field. So i must use the format file to handle this. So please suggest me , why the first record skipped always when i use the above format file.
    If i give the "FirstRow=1" in bulk insert, it shows the "String or binary data would be truncated.
    The statement has been terminated." error. I have checked the datatype length.
    Please update me the solution.
    Regards,
    Selvam. M

  • Bulk Insert to oracle DB from flat file using C#

    I am using odp.net to connect to an oracle database for a C# console application. I have a fixed width file from which the values have to be inserted to multiple tables in oracle database. The data should be bulk inserted as there are lots of records and
    no tools should be used. Please let me know the efficient way to do this task with C#.

    Your question is how to load data from a text file into arrays?
    Start with a
    StreamReader to read the file one line at a time.  Then break each line into individual values, and add each value to a
    List<T>.  Then call .ToArray() on each list to set the value of each array-bound parameter.
    David
    David http://blogs.msdn.com/b/dbrowne/

  • File access problem while using BULK INSERT

    I'm creating a script to automatically convert a large mess of data.  Here's a test query I was using to bring a file into the database:
    INSERT [ImportTestTable]
    SELECT a.*
    FROM
    OPENROWSET(
    BULK 'D:\TestFile.csv',
    FORMATFILE = 'D:\TestStyle.fmt',
    FIRSTROW = 2
    ) AS a;
    SELECT * FROM ImportTestTable
    I've used queries like this on other networks and machines before, but when I run that query on the particular machine I'm working with now, I get the following error:
    Msg 4861, Level 16, State 1, Line 13
    Cannot bulk load because the file "D:\TestFile.csv" could not be opened. Operating system error code 21
    (The device is not ready.).
    Here's some relevant facts I can think of that might help:
    I am running the query from SQL Server Management Studio on a remote machine running Windows 7 Ultimate.  I am connected to this server using SQL authentication.  I believe we are on the same domain / network.  I am not the DBA.  I do
    have the permission "Administer Bulk Operations" explicitly granted to me by the DBA.  The user I am currently logged in as in windows is capable of opening, editing, and saving the file in windows explorer.  The format file is a NON-XML
    format file.
    Any pointers as to where to look for more detailed information would be greatly appreciated!

    I know this is a little old by now, but this is what I used just this week:
    bulk insert [dbo].[Test_Table]
    from 'C:\Documents and Settings\rshuell\Desktop\Test_File.txt'
    WITH (
    FIELDTERMINATOR=',',
    ROWTERMINATOR = '\n',
    KEEPNULLS,
    FIRSTROW=2
    That worked fine for me.
    Of course, we Naomi stated, the file has to be ON THE SERVER.  Or, if you're using an FTP site, for instance, the path would have to point to the FTP site.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • Ignore first row of data file in bulk insert

    Hello
    I use bulk insert to fill a table
    I use code bellow
    bulk insert dbo.test
    from 'c:\test.txt'
    with(FIRSTROW=2,FORMATFILE='c:\test.xml'
    go
    but data inserted to table start from 3throw.
    Could you help me?

    I added that closing parenthesis.
    format file
    <?xml version="1.0"?>
    <BCPFORMAT
    xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <RECORD>
    <FIELD ID="1" xsi:type="CharFixed" LENGTH="6"/>
    <FIELD ID="2" xsi:type="CharFixed" LENGTH="2"/>
    <FIELD ID="3" xsi:type="CharFixed" LENGTH="6"/>
    <FIELD ID="4" xsi:type="CharFixed" LENGTH="13"/>
    <FIELD ID="5" xsi:type="CharFixed" LENGTH="13"/>
    <FIELD ID="6" xsi:type="CharTerm" TERMINATOR="\n"/>
    </RECORD>
    <ROW>
    <COLUMN SOURCE="4" NAME="R3" xsi:type="SQLBIGINT"/>
    <COLUMN SOURCE="5" NAME="R4" xsi:type="SQLBIGINT"/>
    <COLUMN SOURCE="1" NAME="R5" xsi:type="SQLVARYCHAR"/>
    <COLUMN SOURCE="3" NAME="R9" xsi:type="SQLVARYCHAR"/>
    <COLUMN SOURCE="2" NAME="R8" xsi:type="SQLVARYCHAR"/>
    </ROW>
    </BCPFORMAT>
    when I use firstrow=2 it works but do it from 3th row
    bulk insert dbo.test
    from 'c:\test.txt'
    with(FIRSTROW=2,FORMATFILE='c:\test.xml')
    go
    BUT when I use firstrow=1
    bulk insert dbo.test
    from 'c:\test.txt'
    with(FIRSTROW=1,FORMATFILE='c:\test.xml')
    go
    I get thia error
    bulk load data conversion  error(type mismatch or invalid character for the specified codepage)

  • Obtaining a rowcount from a csv file before bulk insert

    I have a group of csv files that i am bulk inserting into my sql table.  They are varying lengths, but the last seven lines of every file are not lines of data that comply with the format of my table and are causing insert errors.  I know i can
    specify a "lastrow" value for the bulk insert, but my problem is that i need a rowcount before running the statement and I can't seem to figure out a way of getting it with how im accessing the file.  (example below of what i'm doing without
    checking for the qty of rows):
    CREATE TABLE ALLFILENAMES(WHICHPATH VARCHAR(255),WHICHFILE varchar(255))
        --some variables
        declare @filename varchar(255),
                @path     varchar(255),
                @sql      varchar(8000),
                @cmd      varchar(1000),
    @lastrow  integer
        --get the list of files to process:
    SET @path = '\\chewbacca\PlantFloorData\RLData\'
        SET @cmd = 'dir ' + @path + '*.csv /b'
    print @path
    print @cmd
        INSERT INTO  ALLFILENAMES(WHICHFILE)
        EXEC Master..xp_cmdShell @cmd
        UPDATE ALLFILENAMES SET WHICHPATH = @path where WHICHPATH is null
        --cursor loop
        declare c1 cursor for SELECT WHICHPATH,WHICHFILE FROM ALLFILENAMES where WHICHFILE like '%.csv%'
        open c1
        fetch next from c1 into @path,@filename
        While @@fetch_status <> -1
          begin
      set @lastrow = 3 -- for now just to make sure logic below works
      print @lastrow
     --bulk insert won't take a variable name, so make a sql and execute it instead:
           set @sql = 'BULK INSERT HMIDATA.dbo.RawData FROM ''' + @path + @filename + ''' '
               + '     WITH ( 
                       FIELDTERMINATOR = '','', 
                       ROWTERMINATOR = ''\n'', 
                       FIRSTROW = 2 ,
       LASTROW = ' + STR(@lastrow) + '
        print @sql
        exec (@sql)
          fetch next from c1 into @path,@filename
          end
        close c1
        deallocate c1
        --Extras
        --delete from ALLFILENAMES where WHICHFILE is NULL
        --select * from ALLFILENAMES
        drop table ALLFILENAMES

    You could do a SELECT COUNT(*) FROM OPENROWSET(BULK), but you would need a format file that specifies a single-field record format with \r\n as the terminator. With the COUNT(*) you could determine the correct value for LASTROW.
    You could also load the entire file into a two-column table where one column is an IDENTITY column and the other is the raw data from the line in the file. And then you could crack the good rows.
    ...or you could write a client-side program or a SSIS package for the task.
    Erland Sommarskog, SQL Server MVP, [email protected]

Maybe you are looking for

  • I am trying to locate an HP Photosmart 7960 printer install disk. Any ideas how to get?

    Two questions.... I have an HP Photosmart 7960 printer and we have a new computer. We cannot find the install disk. I called HP and after about 2 hours of "help" was told that they can't support the printer anymore - it's too old. None of the on-line

  • How do I find out what the name of the reports server  is?

    Hi Everyone, I am connecting to a remote machine using gotomypc.com and have started up Reports Builder 10g. I know very little about installation of Oracle on this machine. Just enough to log into Oracle 10g and run tools like the Report Builder, TO

  • Layered Menu Not Working

    I'm working through the Apple Pro Series DVDSP 3 and the lesson requires me to create a layered menu. The picture in the book shows how the rollover is supposed to work--a new image appears when the user rolls over the button. But that doesn't happen

  • Password problem in oracle 10g after upgrading from oracle 9i

    Hi to all, i'm migrating oracle 9i to oracle 10g. in oracle 9i username/password are same character(eg kareem/kareem) after upgrading to oracle 10g will it create any problem. Because in oracle 10g the condition is when creating user is username and

  • Computer-to-computer via PATCH-STP cable

    I am struggling with a few kinds of, computer-to-computer network issues. I am trying to do some sharing between a Mac Pro Intel (late 2007 2 x 2.66 GHz Dual-Core) and a white MacBook (early 2010 2.26 GHz Intel Core 2 duo), both OSX 10.6.5 via a cabl