• urso47 (12/31/2012)


    Based on the first file you created for me (treating the header), I made some changes (including the path) for using the real file (atached). When I run "EXEC dbo.GetFileType01 'C:\temp\sm\urso47Test02.csv'" (the real file now is "02"), I get the error message:

    Msg 50000, Level 18, State 1, Procedure GetFileType01, Line 123

    ERROR:[GetFileType01]Incorrect header for file C:\temp\sm\urso47Test02.csv

    Acording with CTRL+G = 123, the error is somewhere out here:

    RAISERROR('ERROR:[%s]Incorrect header for file %s',18,1,@ProcName,@pFullPath);

    Maybe one critical change I did should be replacing ":" by "." because I don't have the colon sign at the first header line:

    WHEN RowNum = 1 AND LineData LIKE '[#Lista Estat].%'

    THEN LTRIM(RTRIM(SUBSTRING(LineData,CHARINDEX('.',LineData)+1,8000)))

    You're just missing a little attention to detail. Look at the first line in the file you attached and tell me how many square brackets there are on that line. 😉 Once you fix that and before you run into the next problem with a similar error, look at line 7 in the file for the same problem and fix the related code.

    As a side bar, it IS nice to see that the error checking I wrote does work correctly. 😉

    By the way for my level, this script is hard to understand, what level is this in the SQL world?

    I'm probably the wrong person to be answering that question. If I had to judge on a linear scale of 1 to 10 of what I think an SQL Developer should know and not including the code for the DelimitedSplit8K function, I'd have to give it somewhere between a 5 and a 7 depending on how much they've studied on their own. In other terms, this should actually be fairly simple for someone with 2-4 years experience. For someone new at it, though, the code will seem like a 15 out of 10 at first.

    With that thought in mind, I think you're doing just fine. Keep chipping away at the problem and with all that you're learning in this trial by fire (the same way I learned it, BTW), people will be fighting over who gets you if you ever need another job. 🙂

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)