Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6068377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:42:31+00:00 2026-05-23T09:42:31+00:00

I am trying to do a BULK INSERT operation on SQL Server 2008 R2

  • 0

I am trying to do a BULK INSERT operation on SQL Server 2008 R2 using a parameter. However, I am having problems that the function expects a STRING where I’m passing it a VARCHAR. My SQL is below.

DECLARE @filepath VARCHAR(30)
DECLARE @current_symbol VARCHAR(30)

DECLARE symbol_cursor CURSOR FOR
SELECT symbol FROM stocks.dbo.description WHERE 1=1

OPEN symbol_cursor;

FETCH NEXT FROM symbol_cursor INTO @current_symbol

WHILE @current_symbol is not null
BEGIN
SET @filepath = 'C:\Users\stkerr\Desktop\stockPricing\' + @current_symbol + '.prices'
BULK
INSERT stocks.dbo.pricing
FROM @filepath
WITH
(
    FIRSTROW = 2,
    FIELDTERMINATOR=',',
    ROWTERMINATOR='\n',
    ORDER   ( [date], [open], high, low, [close],volume),
        ERRORFILE='C:\Users\stkerr\errors.txt'.
)

FETCH NEXT FROM symbol_cursor INTO @current_symbol
END 
GO

The problem is popping up when I’m executing the SET @filepath statement.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:42:31+00:00Added an answer on May 23, 2026 at 9:42 am

    In order to specify the file in a variable (@filepath) to BULK INSERT, you will need to construct dynamic TSQL and execute it.

    e.g.

    DECLARE @str_command nvarchar(150)
    SET @str_command = 'BULK INSERT [Customer_Sample] FROM ''' + @SourceFilePath + 
                       ''' WITH (formatfile = ''' + @FormatFilePath + 
                       ''', firstrow =' + cast(@RowNumber as nvarchar) + ')'
    EXEC SP_EXECUTESQL @str_command
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to perform a bulk insert onto SQL Server: BULK INSERT SampleData
I’m trying to bulk insert data to SQL server express database. When doing bcp
I am trying to insert a .csv file into SQL Server 2008 R2. The
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to perform a single boolean NOT operation, it appears that under MS SQL
I'm trying to use a BULK INSERT statement to populate a large (17-million-row) table
I'm trying to do a huge bulk insert into an SqlCe database (version 3.5,
While trying to bulk insert 3M records from CSV file to SQLExpress database the
I'm trying to create a bulk edit page for an app that I'm working
Trying to setup an SSH server on Windows Server 2003. What are some good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.