Results 1 to 8 of 8

Thread: select into

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    163

    Question select into

    I've done a select ... into via

    VB Code:
    1. SqlCmd = "select LoanNumber, [Date], Status, MSI into #tempLoanStatus " & _
    2.          "from MonthlyData " & _
    3.          "where Shelf = '" & ShelfToPRocess & "'" & _
    4.          "order by LoanNumber, [Date]"
    5.  
    6. Set cmdGetLoanData = New ADODB.Command
    7. cmdGetLoanData.ActiveConnection = cnRFCData
    8. cmdGetLoanData.CommandTimeout = 0
    9. cmdGetLoanData.CommandText = SqlCmd
    10.  
    11. 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

  2. #2
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    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...

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: select into

    What is the backend database - ACCESS or MS SQL?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    163

    Re: select into

    ms sql

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    163

    Re: select into

    no, i just want to process the data in the recordset to produce various reports

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    163

    Resolved 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
  •  



Click Here to Expand Forum to Full Width