|
-
Apr 11th, 2005, 11:53 AM
#1
Thread Starter
Addicted Member
select into
I've done a select ... into via
VB Code:
SqlCmd = "select LoanNumber, [Date], Status, MSI into #tempLoanStatus " & _
"from MonthlyData " & _
"where Shelf = '" & ShelfToPRocess & "'" & _
"order by LoanNumber, [Date]"
Set cmdGetLoanData = New ADODB.Command
cmdGetLoanData.ActiveConnection = cnRFCData
cmdGetLoanData.CommandTimeout = 0
cmdGetLoanData.CommandText = SqlCmd
Set rsLoanTemp = cmdGetLoanData.Execute
and this would seem to work as it takes a few minutes to execute and no errors are returned (not necessarily a good assumption) but the question is: how do i then access the temp table #tempLoanStatus. i need to use the results in other sql selects. i tried to create a recordset via rsLoanTemp.Open etc but I keep getting a timeout error hence the command object
-
Apr 11th, 2005, 12:41 PM
#2
Frenzied Member
Re: select into
Hmmm. I would be tempted to say that you can't, but I'm not certain.
You might be able to do it with a global temporary table, but, again I doubt it.
You have a few alternatives (as I see it):
1. Create a permanent table temporarily (i.e. using CREATE TABLE...), use it for your queries, and then DROP it.
2. Return the records in a recordset and manipulate them client-side.
3. Do all the manipulation you need to do in a stored proc, server-side using either a temp table or a Table variable.
Personally I would go for #3, but it really depends on what you want to do with the data...
-
Apr 11th, 2005, 01:19 PM
#3
Re: select into
What is the backend database - ACCESS or MS SQL?
-
Apr 11th, 2005, 01:33 PM
#4
Thread Starter
Addicted Member
-
Apr 11th, 2005, 01:37 PM
#5
Re: select into
Using STORED PROCEDURES in MS SQL is a nice way to build temporary tables (or even TABLE VARIABLES - quicker and less burden to the SERVER) and then process multiple RECORDSETS from that TEMP TABLE.
Then using the ADO command object you can EXECUTE that SPROC and have it return all the recordsets in one call.
Are you looking to have the TEMPORARY table around for a very long time in the program?
-
Apr 11th, 2005, 02:24 PM
#6
Thread Starter
Addicted Member
Re: select into
no, i just want to process the data in the recordset to produce various reports
-
Apr 11th, 2005, 03:06 PM
#7
Re: select into
In query analyzer create a STORED PROCEDURE - something like:
I'm guessing at some of the datatypes and what not...
Code:
Create Procedure DoStuff @Shelf varchar(10)
As
Set NoCount On
Declare @TblVar Table (LN somedatatype, LoanDate datetime
, Stat varchar(1), MSI varchar(10))
Insert Into @TblVar Select loanNumber, [Date], Status, MSI
From MonthlyData Where Shelf=@Shelf
Select * From @TblVar Order by LN,LoadDate
Select ...
Go
This creates a STORED PROCEDURE - you EXECUTE it with the .EXECUTE method of the COMMAND object in VB.
It's parameterized - so you pass in the SHELF to process.
It can do more than one SELECT - it's the way to go with MS SQL Server.
Hope this helps.
-
Apr 11th, 2005, 04:13 PM
#8
Thread Starter
Addicted Member
Re: select into
helps greatly!! thank you
Last edited by john24; Apr 11th, 2005 at 05:20 PM.
Reason: resolved
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|