Get System Stored Procedure Data in variables

Hello all Forum Members,
I am new to SQL Server.
My Requirement is that i want to get sp_helpuser procedure data in select query variables.
is it Possible?
Please Help.

Hi Prashanth,
It works  as per my requirement.
But, Can it be achieved without creating table type variable i.e by creating simple variables ?
Thanks very much for the reply.
its possible to get stored procedure resultset using a select as per method 2 below
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx
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

  • Creation of System Stored Procedure in SQL Server 2012 & SQL Server 2012 R2.

    Hi all,
    I am stuck at a point I am looking for a system stored procedure named 'sp_dboption' in SQL Server 2012  & R2 but could not find.
    Searched for it on the net and found that, this stored procedure 'sp_dboption' is now obsolete. So I tried to copy the content of 'sp_dboption' stored procedure from SQL Server 2008 R2 and create new system stored procedure with this name 'sp_dboption' in
    SQL Server 2012 but was unable to create the system stored procedure.
    Can you guys please tell me how to create system stored procedure in SQL Server 2012 & SQL Server 2012 R2. The reason of why I want to achieve this is because I have used 'sp_dboption' system stored procedure  in my application to create a database.
    As 'sp_dbotion' stored procedure is present in SQL Server 2008 R2 I am able to create the database in SQL server 2008 R2 but not in SQL server 2012.
    Can you please guide me how to create system stored procedure. I am out of luck.
    Please assist me, thanks & looking for help at the earliest. Hope someone will come to the fore and help me.

    Hi Vishwajeet,
    If you tried to create any object in the sys schema, you will get the error below.
    The specified schema name "sys" either does not exist or you do not have permission to use it.
    So I am afraid creating any object in sys schema is not supported by SQL Server. Here is a similar link for your reference.
    How to create table in SYS schema in SQL Server?
    Though sp_dboption is not in SQL Server 2012, does creating a user-defined one with the same content in 2008 make any difference in your business? You just need to specify the fully qualified name dbname.dbo.sp_dboption.
    If you are still interested in creating a system sp_dboption, you can register it with the
    sp_ms_marksystemobject.
    See
    Creating Your Own SQL Server System Stored Procedures.
    Eric Zhang
    TechNet Community Support

  • Replicating System Stored Procedures in MSA Setup

    I started replicating system stored procedures in my MSA environment due to the fact that commands such as sp_rename was not making it to my MSA server. This caused some issues downstream resulting in the DSI goign down and having to manually apply these statements on the target server.
    My question is, are there any cons/drawback to enabling such option
    In reading the manual one of the requirements was that
    Make sure that both the primary and replicate data servers are the same version of Adaptive Server.
    I am Replication from Sybase Cluster Edition 15.7 SP131 to Sybase SMP 15.7 SP131. So far I have not encountered any issues but I don't like surprises.
    Other requirements are met
    When replicating DDL – the primary and replicate databases must have the same login names and passwords; the DSI uses the original server login name and password to log in to the replicate database.
    For me the logins are identical on both servers so this is not an issue
    To replicate DDL and system procedures:
    Mark the primary database using sp_reptostandby.
    Set the RepAgent parameter send warm standby xacts to true—even if there is no standby database
    I also have a warm standby setup and I am using the logical connection as the primary dataserver so these conditions are also met
    Thanks

    I started replicating system stored procedures in my MSA environment due to the fact that commands such as sp_rename was not making it to my MSA server. This caused some issues downstream resulting in the DSI goign down and having to manually apply these statements on the target server.
    My question is, are there any cons/drawback to enabling such option
    In reading the manual one of the requirements was that
    Make sure that both the primary and replicate data servers are the same version of Adaptive Server.
    I am Replication from Sybase Cluster Edition 15.7 SP131 to Sybase SMP 15.7 SP131. So far I have not encountered any issues but I don't like surprises.
    Other requirements are met
    When replicating DDL – the primary and replicate databases must have the same login names and passwords; the DSI uses the original server login name and password to log in to the replicate database.
    For me the logins are identical on both servers so this is not an issue
    To replicate DDL and system procedures:
    Mark the primary database using sp_reptostandby.
    Set the RepAgent parameter send warm standby xacts to true—even if there is no standby database
    I also have a warm standby setup and I am using the logical connection as the primary dataserver so these conditions are also met
    Thanks

  • MS SQL Server system stored procedures can't be migrated into Oracle 11g

    During database migration from MS SQL Server 2008 to Oracle 11g R2, if the application stored procedure invokes the MS SQL Server system stored procedures (for example: sp_getapplock, sp_releaseapplock ....), these SQL server system stored procedures can't be transferred. See following migrated Oracle application stored procedure for example:
    create or replace
    PROCEDURE spPwSysID_GetNextID
    v_ID OUT NUMBER,
    iv_SysType IN NVARCHAR2 DEFAULT NULL ,
    iv_Cnt IN NUMBER DEFAULT NULL
    AS
    v_SysType NVARCHAR2(50) := iv_SysType;
    v_Cnt NUMBER(10,0) := iv_Cnt;
    v_result NUMBER(10,0);
    BEGIN
    --SQL Server BEGIN TRANSACTION;
    utils.incrementTrancount;
    v_Systype := UPPER(v_Systype) ;
    IF v_Cnt < 1 THEN
    v_Cnt := 1 ;
    END IF;
    v_result :=sp_getapplock(v_Resource => v_Systype,
    v_LockMode => 'Exclusive') ;
    IF v_result >= 0 THEN
    BEGIN
    SELECT ID
    INTO v_ID
    FROM PWSYSID
    WHERE SysType = v_SysType;
    IF SQL%ROWCOUNT = 1 THEN
    UPDATE PwSysID
    SET ID = ID + v_cnt
    WHERE SysType = v_SysType;
    ELSE
    BEGIN
    INSERT INTO PwSysID
    ( ID, SysType )
    VALUES ( v_cnt + 1, v_SysType );
    v_ID := 1 ;
    END;
    END IF;
    v_result :=sp_releaseapplock(v_Resource => v_Systype) ;
    END;
    ELSE
    BEGIN
    raise_application_error( -20002, 'Lock failed to acquire to generate Cityworks Id.' );
    END;
    END IF;
    utils.commit_transaction;
    END;

    During database migration from MS SQL Server 2008 to Oracle 11g R2, if the application stored procedure invokes the MS SQL Server system stored procedures (for example: sp_getapplock, sp_releaseapplock ....), these SQL server system stored procedures can't be transferred. See following migrated Oracle application stored procedure for example:
    create or replace
    PROCEDURE spPwSysID_GetNextID
    v_ID OUT NUMBER,
    iv_SysType IN NVARCHAR2 DEFAULT NULL ,
    iv_Cnt IN NUMBER DEFAULT NULL
    AS
    v_SysType NVARCHAR2(50) := iv_SysType;
    v_Cnt NUMBER(10,0) := iv_Cnt;
    v_result NUMBER(10,0);
    BEGIN
    --SQL Server BEGIN TRANSACTION;
    utils.incrementTrancount;
    v_Systype := UPPER(v_Systype) ;
    IF v_Cnt < 1 THEN
    v_Cnt := 1 ;
    END IF;
    v_result :=sp_getapplock(v_Resource => v_Systype,
    v_LockMode => 'Exclusive') ;
    IF v_result >= 0 THEN
    BEGIN
    SELECT ID
    INTO v_ID
    FROM PWSYSID
    WHERE SysType = v_SysType;
    IF SQL%ROWCOUNT = 1 THEN
    UPDATE PwSysID
    SET ID = ID + v_cnt
    WHERE SysType = v_SysType;
    ELSE
    BEGIN
    INSERT INTO PwSysID
    ( ID, SysType )
    VALUES ( v_cnt + 1, v_SysType );
    v_ID := 1 ;
    END;
    END IF;
    v_result :=sp_releaseapplock(v_Resource => v_Systype) ;
    END;
    ELSE
    BEGIN
    raise_application_error( -20002, 'Lock failed to acquire to generate Cityworks Id.' );
    END;
    END IF;
    utils.commit_transaction;
    END;

  • System stored procedure

    I am newbee in Oracle.
    Are there any system stored procedures in Oracle to create a file on file system, as in SQL Server such as xsp_UpdateSignalFile, sp_makewebtask.
    Pls advise.
    Thanks

    Thanks for the information.
    I want to create a file on windows file system. Is that feasible? I tried with below code but got errors.....
    PROCEDURE p_testproc
    IS
    v_file UTL_FILE.FILE_TYPE;
    v_filename varchar2(40):='dep.log';
    v_locat varchar2(200):='c:\tmp\';
    BEGIN
    dbms_output.put_line('proc begin.....');
    if UTL_FILE.is_open(v_file) then
    dbms_output.put_line('file opened');
    else
    dbms_output.put_line('file closed');
    end if;
    v_file:=SYS.UTL_FILE.FOPEN(v_locat,v_filename,'w');
    UTL_FILE.FCLOSE(v_file);
    dbms_output.put_line('File has been created');
    END p_testproc;
    Any help would be appreciated.
    Thanks in advance

  • Sending data to mssql stored procedure that accepts variable of text  data

    Hi all
    i have a stored procedure in mssql 2000 whole input parameter is of type text
    how can i send data of type string from java class while calling storedprocedure using callable statement
    if ui use setString() function it gives an exception that data will be trunctated
    com.microsoft.sqlserver.jdbc.SQLServerException: String or binary data would be truncated.
         at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
         at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
         at com.microsoft.sqlserver.jdbc.SQLServerStatement.sendExecute(Unknown Source)
         at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecute(Unknown Source)
         at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(Unknown Source)
         at com.clearcube.util.DMLLayer.processClientRequest(DMLLayer.java:49)
         at com.clearcube.discovery.PushDiscoveryHandler.init(PushDiscoveryHandler.java:90)
         at com.clearcube.discovery.PushDiscoveryController$1.run(PushDiscoveryController.java:113)
         at java.util.TimerThread.mainLoop(Unknown Source)
         at java.util.TimerThread.run(Unknown Source)
    c
    if any one have solution to this problem plz reply me

    my stored procedure accepts input of type text
    i use text type becouse nvarchar is not enough to
    place data.
    and i want to send data that is greater than the
    length of varcharUnder setString in the API:
    "The driver converts this to an SQL VARCHAR or LONGVARCHAR value (depending on the argument's size relative to the driver's limits on VARCHAR values) when it sends it to the database."
    I am not sure what you should use then? Maybe setCharacterStream?

  • Executing a Stored Procedure with OUT Variables

    When you execute a stored proc withi OUT variables, do you have to add in the "Declare" section and "Begin/End" sections? Or can you just use "EXECUTE <stored proc>"??

    When you execute a stored proc withi OUT variables, do you have to add in the "Declare" section and "Begin/End" sections?
    Or can you just use "EXECUTE <stored proc>"?? You mean this?:
    michaels>  create or replace procedure p (o out varchar2)
    as
    begin
       o := 'Some out variable';
    end p;
    Procedure created.
    michaels>  var o varchar2(50)
    michaels>  exec p(:o)
    PL/SQL procedure successfully completed.
    michaels>  print o
    o                                                
    Some out variable                                

  • Tsql stored procedure - passing multiple variables

    Hi,
    I have a dropdown field on a form that allows for multiple
    selects. When I process the form, I currently use CF to dynamically
    generate the sql WHERE clause creating as many AND statements as
    needed.
    I'm migrating to MS SQL 2005 and Stored Procedures on the db.
    I'm trying to create a stored procedure that effectively uses tsql
    to do what CF was doing previously (creating the WHERE clause).
    In the code below, I am passing a char(22) variable called
    Channel. The code below was my initial attempt at trying to create
    the WHERE clause. Most of the code is focused on extracting out the
    individual "Channel" entities. Any thoughts on how to pull this
    together would be GREATLY appreciated!
    I'm need help on the SELECT side, ultimately I'm selecting
    "regions", from "Syndicated", the WHERE is based on the "Channels"
    passed.
    Thanks,
    cfwild

    Hi,
    This was quite the adventure trying to figure this out. I
    learned quite a bit about tsql. Here is the final procedure:
    CREATE PROCEDURE dbo.uspSelectSyndicatedRegion
    @TablePrefix char(7),
    @Category varchar(100),
    @Channel varchar(2000)
    AS
    BEGIN
    SELECT DISTINCT S.Region
    FROM Syndicated S
    JOIN iter_charlist_to_tbl(@Channel, DEFAULT) M
    ON S.Channel = M.str
    UNION
    SELECT ''
    ORDER BY S.Region
    END

  • Not able to get Oracle stored procedure return value passed to Powerbuilder

    I have an Oracle Stored Procedure that receives a string value and returns a string value..  When I call it from Powerbuilder, it executes but does not send the return value of a string back.  I am trying to encrypt a string in Powerbuilder, pass it to a .net web page and then decrypt so I can check the security tables for permissions to view the web page.  I have tried creating a simple stored procedure that takes a string and returns a string to Powerbuilder; but even that is not working.  Any suggesstions?
    Oracle Procedure:
    CREATE OR REPLACE
    PROCEDURE               TESTINOUT_VARCHAR
    ( P_STRING IN VARCHAR2, P_OUT OUT VARCHAR2)
    IS
       BEGIN  
          P_OUT := P_STRING || 'TESTING';
    END TESTINOUT_VARCHAR;
    Powerbuilder Call:
    string p_string ='                                 '
    Declare TestingString procedure for TESTINOUT_VARCHAR(:ls_group, :p_out) using SQLCA
    Execute TestingString;
    IF SQLCA.CODE = 0 THEN
    FETCH TestingString into:p_out;
    End If
    p_string = p_out;

    Hello John,
    I'm not sure if you already found a solution using an ODBC connection.
    Below the solution with an RPC call:
    Create a user object (uo_trans) of type transaction with the following local external function:
    subroutine TESTINOUT_VARCHAR(string P_STRING,ref string P_OUT) RPCFUNC
    Execute this script
    uo_trans l_transaction
    string ls_outparam
    l_transaction = CREATE uo_trans
    // Profile ODBC_ORA
    l_transaction.DBMS = "ODBC"
    l_transaction.AutoCommit = False
    l_transaction.DBParm = "ConnectString='DSN=ODBC_ORA;UID=system;PWD=<xxxxxx>'"
    connect using l_transaction;
    ls_outparam = space (30)
    l_transaction.testinout_varchar( sle_1.text, ls_outparam)
    messagebox("OUT parameter", ls_outparam)
    disconnect using l_transaction;
    DESTROY l_transaction

  • Calling System Stored Procedures (Eg: sp_help)

    Hi,
    Can you help me on how to call the System SPs like sp_help using JDBC?
    I'm using com.sybase.jdbc2.jdbc.SybDriver. I know that this will produce multiple ResultSet. Hope I can use the cstmt.getResultSet() to handle multiple ResultSets.
    Code Snippet:
       try {
             cstmt = con.prepareCall("{call " + env + "..sp_help (" + table + ")}");
             cstmt.setString(1, table);
             if (cstmt.execute()) {
                rs =cstmt.getResultSet();The stmt.execute() is returning false. Can you help me on this!!

    Bhavin:
    You can call any stored procedures or functions which belong to any schema as long as you have thr proper privileges.
    As long as you are granted as the following by SYS or DBA:
    grant execute on ABS to SHAH;
    You should be able to execute ABS regardless what's your client software (VB, JAVA, JSP, or SQLPLUS).
    Jack
    null

  • How to get system time and date with PHP

    Dear Mr.Craig,
      Thanx a lot. We are running SRM 5.0 (RAMP - Implementation).
      My initial requirement is to write a server-side script to display server date and time. Could you give more inside on how to achieve it?
    Regards,
    Deva.

    Perhaps that will help.
    [code]
    <html>
    <h1>Access System time and date</h1>
    <?
         // saprfc-class-library     
         require_once("saprfc.php");
         $sap = new saprfc(array(
       "logindata"=>array(
       "ASHOST"=>"localhost"          // application server
       ,"SYSNR"=>"00"                    // system number
          ,"CLIENT"=>"000"               // client
          ,"USER"=>"bcuser"               // user
          ,"PASSWD"=>"minisap"          // password
         ,"show_errors"=>false               // let class printout errors
         ,"debug"=>false)) ;                     // detailed debugging information
         $result=$sap->callFunction("MSS_GET_SY_DATE_TIME",
            array(     array("EXPORT","SAPTIME",array()),
               array("EXPORT","SAPDATE",array())));
         if ($sap->getStatus() == SAPRFC_OK) {
        echo "Time: ".$result["SAPTIME"];
        echo "<br>Date: ".$result["SAPDATE"];
        echo "<br>or<br>";
        echo "Server is showing: "
             .substr($result["SAPDATE"], 0, 4)
             ."-".substr($result["SAPDATE"], 4, 2)
             ."-".substr($result["SAPDATE"], 6, 2)
             ." and "
             .substr($result["SAPTIME"], 0, 2)
             .":".substr($result["SAPTIME"], 2, 2)
             .":".substr($result["SAPTIME"], 4, 2);
         } else {
              $sap->printStatus();
         $sap->logoff();
    ?>
    [/code]

  • How to get System Time and Date?

    Hi, may i know how do i get the System's current Time and Date?? And i need to format them into 2 separate String, that's Time is a String, Date is another String. Pls guide me. Thanks a lot!

    What's the problem? The previous example was pretty clear. Just adapt it to your purposes...
            Date currentDateAndTime = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
            SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
            System.out.println(dateFormat.format(currentDateAndTime));
            System.out.println(timeFormat.format(currentDateAndTime));

  • Is it possible to get System form Matrix Data in DI API?

    HI,
       i would like to use DI API to get the System Form Matrix ( like Sale Order ) . Is it possible?
       i know that using UI API is most easier way. However, UI API cause extermemly slow perfomance.
       no matter i use Form.Freeze or not. Please Advise
    Thanks
    Gordon
    Edited by: Gordon Ho on May 7, 2009 7:03 AM

    Hi,
    U can access the Sales Order rows using the DI only if its added to the system. U can use the DOCUMENT object and Document.Lines and access the row data. Please check the SDK help file for more information.
    From SDK Help
    Document_Lines is a child object of Documents object and represents the line entries of a document in the Marketing Documents and Receipts module and the Inventory and Production module.
    Vasu Natari.

  • Trouble with stored procedure date parameters in 10.2.0.2

    Hello,
    i have I couple of procedures which were running perfectly on 10.2.0.1.
    After the upgrade to 10.2.0.2 i get the error: ORA-01843: not a valid month ORA-06512: at "MASTERDBI.CREATE_OR_UPDATE_VER_INFO", line 65 ORA-06512: at line 1
    This error is fired up, on an simple insert-stmt within the procedure. That means, that the date-parameter itself ist ok.
    If I set the nls_date_format w/ "alter session...", then the procedure is running like before and everthing is fine. But this causes a big change on other programs. So I tried to set the nls_date_format w/in an schema.logon-trigger. But w/out success. The only solution is to set the nls_date_format explicit like in this example:
    begin
    execute immediate 'alter session set nls_date_format = "dd.mm.yyyy"';
    create_or_update_ver_info(
    10552,
    'VC BK Zuordnung',
    'TEST',
    sysdate,
    1);
    end;
    It seems, that oracle converts the date-param into a string a back again into a date. But, the date format expected is the american date format. The date format delivered is the german format. And this causes the fault.
    Any comments...
    Kind regards
    Harald Simon
    Message was edited by:
    [email protected]
    Message was edited by:
    [email protected]

    Proc:
    PROCEDURE CREATE_OR_UPDATE_VER_INFO
    p_vertrag_id number,
    p_ver_infotyp varchar2,
    p_text varchar2,
    p_zeitstempel date,
    p_benutzer_id number
    ) as
    v_ver_infotyp_id ver_infotypen.ver_infotyp_id%type;
    v_curr_text ver_infos.text%type;
    begin
    -- Ver-Infotyp ermitteln
    begin
    select ver_infotyp_id into v_ver_infotyp_id from ver_infotypen
    where bezeichnung = p_ver_infotyp;
    exception
    when no_data_found then
    raise_application_error(-20005, 'Vertragsinfotyp "' || p_ver_infotyp || '" in Tabelle VER_INFOTYPEN nicht gefunden.');
    end;
    -- Aktuelle Vertragsinfo ermitteln
    begin
    select text into v_curr_text
    from ver_infos
    where gueltig_bis = to_date('31.12.9999', 'dd.mm.yyyy')
    and ver_infotyp_id = v_ver_infotyp_id
    and vertrag_id = p_vertrag_id;
    exception
    when no_data_found then
    null;
    end;
    -- Wenn der vorhandene Vertragsinfotyp der gleiche ist, dann
    -- sofort wieder raus
    if nvl(v_curr_text, '') = nvl(p_text, '') then
    return;
    end if;
    -- Aktuelle VerInfo löschen
    if not v_curr_text is null then
    update ver_infos
    set gueltig_bis = p_zeitstempel
    where gueltig_bis = to_date('31.12.9999', 'dd.mm.yyyy')
    and ver_infotyp_id = v_ver_infotyp_id
    and vertrag_id = p_vertrag_id;
    end if;
    if p_text is null then
    return;
    end if;
    -- Neue Vertragsinfo einfügen, falls es etwas zum Einfügen gibt
    if not p_text is null then
    insert into ver_infos
    vertrag_id,
    ver_infotyp_id,
    gueltig_von,
    text,
    erstellt_am,
    erstellt_durch
    ) values (
    p_vertrag_id,
    v_ver_infotyp_id,
    p_zeitstempel,
    p_text,
    p_zeitstempel,
    p_benutzer_id
    end if;
    end;
    Test:
    begin
    create_or_update_ver_info(
    10552,
    'VC BK Zuordnung',
    'TEST',
    sysdate,
    1);
    end;
    Result:
    ORA-01843: not a valid month ORA-06512: at "MASTERDBI.CREATE_OR_UPDATE_VER_INFO", line 65 ORA-06512: at line 2
    Test2:
    begin
    execute immediate 'alter session set nls_date_format = "dd.mm.yyyy"';
    create_or_update_ver_info(
    10552,
    'VC BK Zuordnung',
    'TEST',
    sysdate,
    1);
    end;
    Result:
    Statement processed in 0,00 sec
    It is nice, is`nt it?
    Harald
    Message was edited by:
    HSimon

  • Stored Procedure with bind variables

    Hello,
    I have problems when executing this sample code:
    Procedure Test (..., in_Param IN CHAR, ...)
    Query_Str := 'Select * from Table1 where column1 IN :in_Param';
    Open Cursor1 For Query_Str Using in_Param;
    This Cursor retuns rows when in_Param is 'A'
    This Cursor does not return any row if in_Param is ('A', 'B')
    Can you please help to track the error in this Query?
    Many thanks

    It seems to be that the bind variable is treated as a single discrete object. Hence
    'Select * from Table1 where column1 IN :in_Param';
    is functionally the same as
    'Select * from Table1 where column1 = :in_Param';
    so when in_Param is ('A', 'B'), what actually gets executed is
    Select * from Table1 where column1 = 'A, B';
    Not surprisingly this returns no rows.
    You can of course do this:
    'Select * from Table1 where column1 in( :x, :y, :z)';
    Open Cursor1 For Query_Str Using :i, :j, :k;
    So you could parse in_param yourself, populating the unused variables with nulls, so that if in_param = ('A, B') then i=A, j=B and k=null. Given that in 8i an IN string can have 1000 variables this could be a right mare if you don't put a cap on in_param.
    Your alternative is not to use a bind variable for this statement.
    rgds, APC

Maybe you are looking for