INSERTING INTO A TEMPORARY TABLE OUT PUT OF BATCH QUERIES

  •  

    Hi GUYS,

    REALLY SO MUCH INTERESTING REQUIREMENT FOR ME

    IAM GIVING SAMPLE TABLES :

    In a table a columns consists the batch sql queries like this

    select * INTO TABLE5 from EMP

    SELECT  * INTO TABLE6 FROM DEPT

    SELECT * FROM TABLE5,TABLE6 WHERE EMP.DEPTNO=DEPT.DEPTNO

    DROP TABLE TABLE5

    DROP TABLE TABLE6

    example:TABLE10

    COLUMNS:

    col1 : 1

    col2:

    "select * INTO TABLE5 from EMP

    SELECT  * INTO TABLE6 FROM DEPT

    SELECT eno,ename,dname FROM TABLE5,TABLE6 WHERE EMP.DEPTNO=DEPT.DEPTNO

    DROP TABLE TABLE5

    DROP TABLE TABLE6"

    In a query analyzer i have written like this

    declare @s-2 varchar(8000)

    select @s-2=col2 from TABLE10

    exec sp_executesql @s-2

    Iam getting the output of eno,name,dname from both the tables(THIS IS THE QUERY WHICH IAM GETTING THE OUTPUT :SELECT eno,ename,dname FROM TABLE5,TABLE6 WHERE EMP.DEPTNO=DEPT.DEPTNO)

    I WANT TO insert into a temporary table the output of the above data .

    How to insert into a table ?

     

     

     

  • Check out INSERT INTO and SELECT INTO in BOL - they will both insert records into a table.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Also check out the temporary tables and table data type entries in BOL.  This may be a good to use the table data type. 

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • There's been times I've wanted to insert the results from a stored procedure into a temporary table also. I don't think there is a way. Maybe someone does????

  • CREATE TABLE #Temp (

    ... -- columns matching output of stored proc

    )

    INSERT INTO #Temp

      EXEC StoredProcedure @params ...

    The limitation is that the stored proc must return only one reordset.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • And you MUST use a proper temp table (starting with #), not a table variable (starting with @)

  • THANK U GUYS FOR YOUR ANSWERS

    insert into TEMPORARYTABLE exec sp_executesql @sqlquery

    This temporary table will have the definition exactly which is the output of @sqlquery.

    LIKE THIS I HAVE DONE

     

     

  • Thank you!

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply