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
here is what i did!
thank you everyone for your extraordinary help!
i went with a permanent table and just keep dropping it!