Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2006
    Posts
    11

    Unanswered: Must declare the scalar variable Error

    Hi All,

    I'm totaly new to administrating databases.

    All I want to do is run the sql server script located at http://www.data-miners.com/sql_companion.htm#downloads.

    This creates some tables and uploads a series of text files into them.

    When I run the script through SQL Server Express 2005 I get the error
    Must declare the scalar variable "@DATADIR".
    I suspect it's something with me putting in the wrong path.

    The text files that the script needs to load into the table are located on the K drive, and I have changed the path in

    Code:
    declare @DATADIR varchar(128)
    set @DATADIR='C:\gordon\book\data\final\textfiles'
    to

    Code:
    declare @DATADIR varchar(128)
    set @DATADIR='k:\textfiles'
    I suspect this is the wrong syntax that's why it's not working but I might be totally wrong.

    The text file and the server are both saved on the k drive.

    Regards,

    Seaweed

  2. #2
    Join Date
    Nov 2006
    Posts
    11

    Figured

    Well,

    I finaly figured something out but I don't know why it works.

    The (full) script in the prior post looks like it is in two sections: creating the table and then loading the data into the rows.

    So removed the section for loading the data and just ran the part for creating all the table, description etc and that worked fine. Then I ran the other half of the script for loading the data seperatly and that went well although it took about 2 hours and here's the bit of code I for the path

    Code:
    declare @DATADIR varchar(128)
    set @DATADIR='k:\textfiles'
    Which I couldn't get to work before for some reason (only if I seperate out the code as described above). Now I'm new to this but does anyone know why it worked like this...because I haven't got a clue

    Seaweed

    PS Im using MS Server Express 2005

  3. #3
    Join Date
    Mar 2010
    Posts
    1
    hey.. doesnt work with me.. need your guidance in this.. am new to SQL.

  4. #4
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Drop the database, remove "go" from the script, and re-run it.
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

Posting Permissions

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