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

  • SEARCH
  • Home
  • 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 6085875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:41:18+00:00 2026-05-23T11:41:18+00:00

Im using Sql2008 trying to run this BCP command but it never creates the

  • 0

Im using Sql2008 trying to run this BCP command but it never creates the file.

-- Export query
  DECLARE @qry2 VARCHAR(1000)
  SET @qry2 = 'SELECT * FROM @SkippedProductsTable'

  -- Folder we will be putting the file in         
  DECLARE @incomingfolder VARCHAR(1000)
  SET @incomingfolder = 'c:\Logs'

  DECLARE @bcpCommand VARCHAR(2000)
  SET @bcpCommand = 'bcp "'+@qry2+'" queryout "'+@incomingfolder+'\SkippedProducts-'+CAST(@StoreMatchCode AS VARCHAR)+'-'+'.txt" -c -T'

  PRINT @bcpCommand
  EXEC MASTER..xp_cmdshell @bcpCommand, no_output

The created command looks like:

bcp "SELECT * FROM @SkippedProductsTable" queryout "c:\Logs\SkippedProducts-1330-.txt" -c -T

Can anyone suggest what could be going wrong? I’ve never used BCP before and not really sure where to start looking.

As a start I know that the folder deffinately exists at that location

  • 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-23T11:41:19+00:00Added an answer on May 23, 2026 at 11:41 am

    I think the problem is the SELECT.

    You are SELECTing from a table variable that is not declared in the query, so there’s nothing for BCP to do.

    Table variables only persist for the context they are called in, so even if you have one in a query, and you have dynamic sql or a subproc within that first query, they won’t be able to see the table variable.

    See this for more info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL2008, I'm trying to figure out an efficient query to find a row
i´m using subsonic 3 trying convert a SQL2008 project to MySQL. when the projects
I'm trying to troubleshoot this problem using SQL Profiler (SQL 2008). After days of
I am trying to connect to the database but I am getting this exception:
HI all, Iam using VS2008 and SQL2008 i want to access my stored procedures
I have a txt file that I’m trying to import as flat file into
I'm trying to delete a couple of rows USING SQL Server management studio, for
I'm trying to see if anyone knows how to cluster some Lat/Long results, using
I have a .net application using sql server 2005 database. This is a very
Trying to create a user account in a test. But getting a Object reference

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.