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 8090997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:54:54+00:00 2026-06-05T19:54:54+00:00

i would like to do this: DECLARE @TmpTable TABLE = select * from someTable

  • 0

i would like to do this:

DECLARE @TmpTable TABLE = select * from someTable where someTable.Column1='BLAH'

i need @TmpTable to be a subset of someTable and i don’t want to implicitly declare a structure with fields for @TmpTable, rather i want it to be dynamically created from someTable.

is this possible?

thanks so much for you help and guidance!

i’ve taken the suggestion to try the temporary table. however, i am getting the error:

  The table #SubSet does not exist in the database

here’s the code:

DECLARE @StartDT DATE
DECLARE @MinDOS DATE
SELECT @MinDOS = MIN(dos) FROM accn_demographics
SELECT @StartDT = 
    CAST(CAST(datepart(YYYY,@MinDOS) AS varchar) + '-' + CAST(datepart(mm,@MinDOS) AS varchar) + '-' + CAST('01' AS varchar) AS DATETIME)
DECLARE @FileLocation VARCHAR(50)
DROP TABLE #SubSet
WHILE @StartDT < '20110901'
BEGIN
    SELECT * 
        INTO #SubSet
    FROM ViewAccountDetail
    WHERE datepart(yyyy,ViewAccountDetail.DOS) = datepart(yyyy,@StartDT)
        AND datepart(mm,ViewAccountDetail.DOS) = datepart(mm,@StartDT)
    SET @FileLocation='C:\test\'+'ViewAccountDetail'+cast(@StartDT as varchar)+'.csv'
    EXEC BCP_Text_File #SubSet, @FileLocation       
    SET @StartDT = DATEADD(MONTH,1,@StartDT)

    DROP TABLE #SubSet
END
  • 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-06-05T19:54:56+00:00Added an answer on June 5, 2026 at 7:54 pm

    here is what i did!

    DECLARE @StartDT DATE 
    DECLARE @MinDOS DATE 
    SELECT @MinDOS = MIN(dos) FROM accn_demographics 
    SELECT @StartDT = 
    CAST(CAST(datepart(YYYY,@MinDOS) AS varchar) + '-' + CAST(datepart(mm,@MinDOS) AS varchar) + '-' + CAST('01' AS varchar) AS DATETIME) 
    DECLARE @FileLocation VARCHAR(50) 
    DROP TABLE #SubSet 
    WHILE @StartDT < '20110901' 
    BEGIN 
    SELECT * 
    INTO SubSet 
    FROM ViewTransactionDetails 
    WHERE datepart(yyyy,ViewTransactionDetails.DOS) = datepart(yyyy,@StartDT) 
    AND datepart(mm,ViewTransactionDetails.DOS) = datepart(mm,@StartDT) 
    SET @FileLocation='C:\test\'+'ViewTransactionDetails'+cast(@StartDT as varchar)+'.csv' 
    EXEC BCP_Text_File SubSet, @FileLocation    
    SET @StartDT = DATEADD(MONTH,1,@StartDT) 
    
    DROP TABLE SubSet 
    END
    

    thank you everyone for your extraordinary help!

    i went with a permanent table and just keep dropping it!

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

Sidebar

Related Questions

I would like do some thing like this: SELECT sum(quantity) FROM orders WHERE order_code
I would declare an empty String variable like this: string myString = string.Empty; Is
I've got a table in SQL 2008 that looks like this: DECLARE @DataTable TABLE
I have written my own function, which in C would be declared like this,
I would like to have the form object like this: public class FormData {
I would like to sort a list like this: <ul> <li>L</li> <li>S</li> <li>XXS</li> <li>XS</li>
I would like to have declaration like this: void Date::get_days_name(const Date& = this) which
I would like to do something like this i.e., use wild card characters in
I would like to know which tags I should use for layout like this.
I would like to send a html string with a GET request like this

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.