How to Store the result sets of a stored procedure that is returning more that one result set in two different table ?

Hi Experts,
   I have on stored procedure which returns mote than one resultset i want that to store in two different temp table how can achieve this in SQL server.
 following is the stored procedure and table that i need to create.
create procedure GetData as begin select * from Empselect * from Deptend 
create table #tmp1 (Ddeptid int, deptname varchar(500),Location varchar(100))
Insert into #tmp1 (Ddeptid , deptname ,Location )
exec GetData
create table #tmp (empid int , ename varchar(500),DeptId int , salary int)
Insert into #tmp (empId,ename,deptId,salary)
exec GetData
Niraj Sevalkar

You cant get two resultsets out of SP like this. The workaround is to merge and bring the resultsets.
For this number of columns as well as corresponding datatypes have to be compatible. Also you will need one additional column which indicates resultset value. Then use this as filter to get your desired resultset out
create procedure GetData as
begin
select 'resultset1' as Cat,*,.. N columns from Emp
union all
select 'resultset2' as Cat,*,.. N columns from Dept
end
create table #tmp1 (Ddeptid int, deptname varchar(500),Location varchar(100))
Insert into #tmp1 (Ddeptid , deptname ,Location )
Select column1,column2,column3
from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
Integrated Security=SSPI','Execute yourdb..GetData')
WHERE Cat = 'resultset1'
create table #tmp (empid int , ename varchar(500),DeptId int , salary int)
Insert into #tmp (empId,ename,deptId,salary)
Select column1,column2,column3, column4
from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
Integrated Security=SSPI','Execute yourdb..GetData')
WHERE Cat = 'resultset2'
also see
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx
Another method is to populate table with relevant resultset within procedure itself and then select from the table directly outside.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • How to config the digital write-to-line so it would independent when more than one is being used

    when one digital wirte-to-line is used in the labview vi, a good logic high(5v) can be read using a voltmeter,but when two or more digital write-to-lines are being using at the same time,the logic high seemed to have split voltages and thus having a bad logic high.how to make sure that in the labview program,that when many digital write-to-lines are used at the same time,all of them can abtain a good logic high (around 5v).
    I need the solutions urgently.
    grays
    np

    Hello,
    The probable reason you are seeing the behavior you are is due to a reconfiguration of the digital port. The Write to Digital Port VI is setup to configure the entire port, then write to one line (default settings). If you reconfigure the port it will reset all the lines, and then write your new value. You will want to use the iteration input on the Write to Digital Line so you can avoid the reconfiguration issue.
    The first time the Write to Digital Line is executed in your code wire a 0 to the iteration (or leave it unwired). This will configure the port for write and write your first value. The next time you use the write to digital port VI wire an integer greater than 0. This will bypass the configuration step and simply write the new value to the
    line. You can open the Write to Digital Line VI to see how the iteration input effects the execution and configuration of the digital ports.

  • How to retrieve the outer parameter of a stored procedure in XSQL page

    I have to call a stored procedure in the xsql page that returns a resultset (ie. oracle table/record type) through an outer paramter. Is there any built-in xsql action tag available to get the parameter and present
    it in xml on the page? please help, thanks.

    You cant get two resultsets out of SP like this. The workaround is to merge and bring the resultsets.
    For this number of columns as well as corresponding datatypes have to be compatible. Also you will need one additional column which indicates resultset value. Then use this as filter to get your desired resultset out
    create procedure GetData as
    begin
    select 'resultset1' as Cat,*,.. N columns from Emp
    union all
    select 'resultset2' as Cat,*,.. N columns from Dept
    end
    create table #tmp1 (Ddeptid int, deptname varchar(500),Location varchar(100))
    Insert into #tmp1 (Ddeptid , deptname ,Location )
    Select column1,column2,column3
    from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
    Integrated Security=SSPI','Execute yourdb..GetData')
    WHERE Cat = 'resultset1'
    create table #tmp (empid int , ename varchar(500),DeptId int , salary int)
    Insert into #tmp (empId,ename,deptId,salary)
    Select column1,column2,column3, column4
    from OPENROWSET('SQLOLEDB','Data Source=Server_name;Trusted_Connection=yes;
    Integrated Security=SSPI','Execute yourdb..GetData')
    WHERE Cat = 'resultset2'
    also see
    http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx
    Another method is to populate table with relevant resultset within procedure itself and then select from the table directly outside.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to Create a Procedure/Function to Return more than one value

    How I can write a function/Procedure to which one value is passed and it will return nine values. How I can use these values

    Syed,
    I would use PL_SQL table versus a VARRAY for this purpose as you will have an advantage of joining PL_SQL table if you want to in your SQL statements in the procedure.
    1. At the SQL prompt, create a type using,
       create or replace type myTable as table of VARCHAR2(100);
    2. Pass the table to your procedure as IN OUT parameter,
    Create or replace procedure
    myProc(pvar1 IN Number, passingArray IN OUT myTable) AS
    Begin
        --Fill the array with your logic
        for i in 1..9
        loop
            passingArray.extend;
            passingArray(passingArray.count) := 'what ever';
        end loop; 
    End;
    3. From your Main prog, you call  Myproc
       --declare a variable for type first
       passingArray myTable := myTable();
       begin
       myProc(10, passingArray());
       --At this point, You would be able to Join the PL_SQL table
       --which gives you the power of using SQL with PL_SQL tables
       end; -- end of main program
    4. All done!I have not shown how to use PL_SQL tables in SELECT statements, as that is not the subject here.
    At the end of the story, I would say, if you know the number of arguments that you are going to pass to a procedure, Simply use "that many" IN OUT parameters to finish your task(9 in your case). Although the proc call looks large with this, it is much simpler. The above approach is VERY helpful if YOU DO NOT KNOW THE NUMBER OF ARGUMENTS that you are sending AND receiving From a procedure.
    Thx,
    SriDHAR

  • HT4436 I have now downloaded all of my CD's to my itunes library and have since only purchased new music using itunes Store.  This itunes library is stored on an old Dell Desktop that I am getting ready to replace with an iMac; how can I move the music? 8

    I have now downloaded all of my CD's to my itunes library and have since only purchased new music using itunes Store.  This itunes library is stored on an old Dell Desktop that I am getting ready to replace with an iMac; how can I move the music? 86GB
    Is the music I downloaded from my CD's already in the iCloud or only the music I purchased on itunes?

    This might help: http://www.macworld.com/article/1146958/move_itunes_windows_mac.html.

  • How to store the value to variable?

    hi
    plz c the below code...
    my prblm is i want to store the value of wa_final-preis into new_xeipa-preis if there is only one ebeln...
    if there are more procss orders then i want to save the first value to new_xeipa-preis wn second record comes then new_xeipa-preis should be replaced by new value and old_xeipa-preis replaced by old value....
    how to do this?
    LOOP AT xeipa INTO wa_xeipa.
      idx = sy-tabix.
      CLEAR: wa_xeina.
        READ TABLE xeina INTO wa_xeina WITH KEY infnr = wa_xeipa-infnr.
        IF sy-subrc is INITIAL.
        wa_final-infnr = wa_xeipa-infnr.
        wa_final-ebeln = wa_xeipa-ebeln.
        wa_final-bedat = wa_xeipa-bedat.
        wa_final-matnr = wa_xeina-matnr.
        wa_final-lifnr = wa_xeina-lifnr.
        wa_final-peinh = wa_xeipa-peinh.
        wa_final-preis = wa_xeipa-preis.        "net price
        wa_final-bprme = wa_xeipa-bprme.
        wa_final-bwaer = wa_xeipa-bwaer.
        IF ( wa_final-infnr is NOT INITIAL ) AND ( wa_final-ebeln is NOT INITIAL ) .
        ABWEICHUNG = ( new_xeipa-preis / old_xeipa-preis ) * 100 .
        ENDIF.
        append wa_final to it_final.
        ENDIF.

    Hi Smitha,
    Check the below given code.
    LOOP AT xeipa INTO wa_xeipa.
      idx = sy-tabix.
      CLEAR: wa_xeina.
        READ TABLE xeina INTO wa_xeina WITH KEY infnr = wa_xeipa-infnr.
        IF sy-subrc is INITIAL.
        wa_final-infnr = wa_xeipa-infnr.
        wa_final-ebeln = wa_xeipa-ebeln.
        wa_final-bedat = wa_xeipa-bedat.
        wa_final-matnr = wa_xeina-matnr.
        wa_final-lifnr = wa_xeina-lifnr.
        wa_final-peinh = wa_xeipa-peinh.
        wa_final-preis = wa_xeipa-preis.        "net price
        wa_final-bprme = wa_xeipa-bprme.
        wa_final-bwaer = wa_xeipa-bwaer.
    " First time this value is not populated. When the second value comes in,
    " New value gets populated in OLD variable and New value is replaced with the latest.
        *IF idx NE 1.*
          *old_xeipa-preis = new_xeipa-preis.*
        *ENDIF.*
        *new_xeipa-preis = wa_xeipa-preis.*
      IF ( wa_final-infnr is NOT INITIAL ) AND ( wa_final-ebeln is NOT INITIAL ) .
        ABWEICHUNG = ( new_xeipa-preis / old_xeipa-preis ) * 100 .
        ENDIF.
        append wa_final to it_final.
        ENDIF.
    ENDLOOP.
    I hope this is what you were looking for.
    Thanks & Regards,
    Ram.
    Edited by: ram Kumar on Jun 12, 2009 5:16 PM

  • How to store the output of a analog to digital converter into an 2D array

    Hi
    I am doing my M.Tech Thesis in Image reconstruction and I am using labview for simulation and I want to know how to store the output of a analog to digital converter into an 2D labview array.

    nitinkajay wrote:
    I want to know how to store the output of a analog to digital converter into an 2D labview array.
    How exactly are you performing 'Analog to Digital'???
    Grabbing image using camera OR performing data acquisition using DAQ card OR some other way????
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.

  • How to multiple/ parellal sets of books to generate more than one financial statement based on different (or the same) accounting principles.

    How to multiple/ parallel sets of books to generate more than one financial statement based on different (or the same) accounting principles.
    My Client needs Parallel Ledger in SAP B1 similar like SAP ECC. Is this functionality available ?

    Dear Mr. Nagrajan,
    Thank you for your response. I have already gone through documents but not able to understand. Is there any setup for this ? or its just work around i.e. using template and special field in JV i.e. Ref. 1 /2
    My doubts :
    I understand that Chart of Account structure is one and common for IFRS and other accounting method. We need to create only those account separately ( 2 times with prefix like IFRS revenue account, GAAP Revenue account).
    Now at time of entry, Assume some entries / adjustment are specifically for IFRS and not for other ledger. In this case, What need to do ?
    You have mentioned about DTW approach but do we need to insert all JV's again with other ledger ?
    Someone suggested that if any entry which are specific to IFRS Ledger, We need to user Ref.1 /2 column or Transcation code column and in which we can put IFRS
    Based on this, Need to create 2 seperate template for IFRS and other ledger for all report.
    This is my understanding of Solution in SAP B1. Please help me to clarify my though process
    Please do needful.If you have done implemenation and if you can share doucment, it would be great help.
    Email :[email protected]

  • How to store the images in Oracle?

    Hi,
    I am a new developer, trying to find out how to store the images in Oracle. Is there anyway that I can store the images in Oracle and insert them into my html file?
    Thanks!
    Sarah

    There is a simple image example available from OTN.
    From the OTN main page, go to Products --> interMedia --> Sample Code. The name of the example is "Load rich media content with a browser."
    This example loads and retrieves an image from an Oracle8i database through a web page using the Oracle interMedia Web Agent.
    Hope this helps.
    null

  • How to store the images in tables

    how to store the images in tables .what is the use of "clob ,blob"

    Using with the CLOB or BLOB, you can store the images in the table.
    Srini C

  • How to store the flat file data into custom table?

    Hi,
    Iam working on inbound interface.Can any one tell me how to store the flat file data into custom table?what is the procedure?
    Regards,
    Sujan

    Hie
    u can use function
    F4_FILENAME
    to pick the file from front-end or location.
    then use function
    WS_UPLOAD
    to upload into
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL FUNCTION 'F4_FILENAME'   "Function to pick file
        EXPORTING
          field_name = 'p_file'     "file
        IMPORTING
          file_name  = p_file.     "file
      CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
         filename                       = p_file1
        TABLES
          data_tab                      = it_line
    *then loop at it_line splitting it into the fields of your custom table.
    loop at it_line.
              split itline at ',' into
              itab-name
              itab-surname.
    endloop.
    then u can insert the values into yo table from the itab work area.
    regards
    Isaac Prince

  • How to store the zip file in oracle table?

    hi,
    How to store the zip file in oracle table ?
    is it possible to unzip and read the file ?
    Thanks
    Rangan S

    SQL> DESC BLOB_TABLE;
    Name Type Nullable Default Comments
    A INTEGER Y
    B BLOB Y
    SQL> INSERT INTO BLOB_TABLE VALUES(5,BLOB('MWDIR_TST','TEST.ZIP'));
    INSERT INTO BLOB_TABLE VALUES(5,BLOB('MWDIR_TST','TEST.ZIP'))
    ORA-00904: "BLOB": invalid identifier
    SQL> INSERT INTO BLOB_TABLE VALUES(5,('MWDIR_TST','TEST.ZIP'));
    INSERT INTO BLOB_TABLE VALUES(5,('MWDIR_TST','TEST.ZIP'))
    ORA-00907: missing right parenthesis
    SQL> INSERT INTO BLOB_TABLE VALUES(5,('\\MWDIR_TST\TEST.ZIP'));
    INSERT INTO BLOB_TABLE VALUES(5,('\\MWDIR_TST\TEST.ZIP'))
    ORA-01465: invalid hex number
    SQL> INSERT INTO BLOB_TABLE VALUES(5,('\\MWDIR_TST\TEST.ZIP'));

  • Chat App: how to store the user IP in database when they login.

    hello,
    i am working on chat application. first i made a login GUI form. after login when we run the Chat program, it ask the ip address of the server to whom it want to connect. and if u enter the ip address, it will connect to the server and chat will begin, thats working perfect.
    but i want to show the list of users who r logged on and when i simply click on the user name, chat should begin.
    i have the logic that when any user log in, then its IP address will be stored in the database. this ip address will shown to the online users.
    but i dont know how to store the user information in database when they log in. can any body suggest me wht lines of code i should use.
    thanks.

    palakk wrote:
    i have the logic that when any user log in, then its IP address will be stored in the database. Bad approach. That will only work if this chat is only intended for use on a LAN. If it's used on the internet, then your users' IP addresses will almost always be either a) those of their routers, or b) private IP addresses, and in both cases, multiple users can have the same IP address.
    this ip address will shown to the online users. Why would you want to do that? I want to chat with "Bill", not with "1.2.3.4".
    but i dont know how to store the user information in database when they log in.Do the same thing that you're currently doing to store the IP address, but with the other information you want to store.
    can any body suggest me wht lines of code i should use. This is not a code writing service.

  • How to store the datas in a .txt file in to a JTable in Java Swing

    Hi sir,
    Here i want to know how to store the data's of a .txt file
    in to a JTable in java swing.
    Where here the .txt file like for eg,spooler.txt is in the server and from there it will come to my client machine what i have to do is to take that .txt file and store the datas of the .txt file
    in a JTable.This is what i want.So pls. do help and provide the code as well.I will be thankful.Since i am involved in a project which involves this it is Urgent.
    Thanx,
    m.ananthu

    You can't just display data from a text file in a JTable. You have you understand the structure of the data so that you can parse the data and create a table model that can access the data in a row/column format. Here is an example of a simple program that does this:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=315172

  • How to store the 2d graphics with matrix?

    Hello everybody,
    I met a problem,and the question is "How to store the 2d graphics with matrix?".
    who can help me?
    Best wishes to all of you.
    James Wei.

    Hello,
    It is possible to store the time in user variables. How to export those variables depends on the deployment of the file.
    Some information about showing elapsed time can perhaps give you a start:
    Display Time Information
    Lilybiri

Maybe you are looking for

  • I'm looking for a scheduling app that will send reminder emails to clients

    I'm looking for an iPad appointment app that will send reminder emails to clients & synch with my iMac. Suggestions?

  • HT3235 DVI to Display port cable

    Hello I have a Mac bookpro model MacBookPro3,1 with NVIDIA GeForce 8600M GT 256 MB graphics Is possible to connect to external display with cable DVI to Display port (not mini display port ) ?

  • How do I upgrade from Lightroom 1 to 4 or 5?

    I have registered my Lightroom 1, but it doesn't show as being registered in Creative Cloud. When I go to add the serial number, it says it's already registered and I can't add it. It's not syncing, even though my email addresses are the same. I figu

  • E-mailed pics

    I got an e-mail from my brother in law with a picture attached. I can open it and view it. How can I save it and make it my wallpaper? any ideas?

  • Macintosh HD boot drive doesn't show up as Startup Disk (but boots fine)?!?

    Hi, My main internal bootable disk (Macintosh HD) does not show up in Systems Preferences > Startup Disk. If I want to boot from it, I have to either hold down the "Option" key at startup (and the disk appears fine, so I select it), or I have to wait