Ignoring blank input parameter in a stored procedure

I'm trying to write a SP that ignores a blank parameter in a
where clause like this.
create procedure blah @myvar int AS
select * from companies
where 1 = 1
if @myvar is <> ''
and id = @myvar
This seems like a simple task but it doesn't work. Thanks in
advance

Assuming SQL Server, you might try something like this:
SELECT *
FROM companies
WHERE id = ISNULL(@myvar, id)
If your @myvar parameter is NULL, then your WHERE clause is
basically
id = id, which makes it a "don't care" condition and returns
all rows as if there was no where clause. You can add other
parameters to your where clause, and they would not be affected, as
this condition would only restrict the selection if @myvar was not
null, otherwise it is "ignored".
Phil

Similar Messages

  • Set Null as Default  for input parameter to a stored procedure

    hi ,
    How can we set default values as NULL to an input parameter in a stored Procedure.
    create or replace procedure emp_proc ( p_test_input in varchar2
                                                        p_emp_id in number,
                                                        p_emp_name in varchar2,
                                                       p_manager_id in number )
    as
      begin
       if ( upper ( p_test_input ) = 'I' )
       then
          insert into emp
          values      ( p_emp_id  ,p_emp_name ,p_Manager_id,sysdate );
       elsif ( upper ( p_test_input ) = 'D' )
       then
          delete from emp
          where       emp_id  = p_emp_id;
       else
          dbms_output.put_line
             ( 'Please input ''A'' for ADD or ''D'' Delete  EMPLOYEE'
       end if;
    end;As Shown above if i want to do only delete operation
    i want to call this procedure like without passing extra parameters .
    EXECUTE  emp_proc('D',1010);Edited by: Rede on May 28, 2010 12:21 PM
    Edited by: Rede on May 28, 2010 12:22 PM

    create or replace procedure emp_proc ( p_test_input in varchar2,
                                                        p_emp_id in number,
                                                        p_emp_name in varchar2 default null,
                                                       p_manager_id in number default null )

  • Pass a datarow as input parameter in a stored procedure

    Hi everyone!
    I wonder if anyone know how to pass a datarow (better if tipized like "tablenameRow") as input parameter for a stored procedure.
    links or suggestions are welcome! (i'm newbie in .net programming, so if you can post some code i'll be really grateful!)
    Thank you!

    Hi,
    YES!! its possible you can pass a datarow to a SP from your Dot net application.
    Here below i'm going to give you an example for Desktop Application.
    For Passing a datarow as Input Parameters, your SP need to support for all these parameters.
    I mean, if a data row has 03 Columns. Then your procedure should be able to take 03 arguments/parameters.
    --Adjust code according to your need.
    --Its for C# Desktop application.
    --Visual Studio Professional, Framework (2.0)
    //Setting connections.
    OracleConnection con=new OracleConnection("Data Source=orcl9i; user id=scott; password=tiger");
    OracleComand cmd=new OracleCommand(con);
    cmd.Type=CommandType.StoredProcedure; //you are useing SP
    cmd.Text="my_stored_procedure"; //Mention SP name.
    --if DataRow has Three columns. You need three parameters.
    OracleParameter p1=new OracleParameter ();//By default parameters are input parameters.
    OracleParameter p2=new OracleParameter ();
    OracleParameter p3=new OracleParameter ();
    //We assume that Datarow already has data in it.
    p1.ParametersName="sp_var1 ";
    p1.OracleDbType=OracleDbType.Varchar;
    p1.Value=tablenameRow[1]; //Here DataRow object's Column1 is input.
    p2.ParametersName="sp_var2 ";
    p2.OracleDbType=OracleDbType.Varchar;
    p2.Value=tablenameRow[2]; //Here DataRow object's Column2 is input.
    p3.ParametersName="sp_var3 ";
    p3.OracleDbType=OracleDbType.Varchar;
    p3.Value=tablenameRow[3]; //Here DataRow object's Column3 is input.
    cmd.OracleParameter.Add(p1); //Add parameters.
    cmd.OracleParameter.Add(p2); //Add parameters.
    cmd.OracleParameter.Add(p3); //Add parameters.
    cmd.ExecuteNonQuery(); //Execute Procedure here.
    Feel free to ask if still found problem.
    ....

  • Can I pass an array as an input parameter for a stored procedure on SQL Server 2000

    I am trying to pass an array to a stored procedure residing on my SQL Server 2000 database server. Is this even possible? If it is possible, what is the syntax for this?
    Any help would be greatly appreciated.
    Thanks

    I have passed arrays to and from a database using SQL and ActiveX, including to and from stored procedures, but I cannot recall the precise method used to do so. If memory serves, everything is in the form of a string. You need to do a lot of parsing and 'unparsing' to get this data into your stored procedure.
    You are left with a couple of options to get your data to the stored procedure. I recommend using SQL in LabVIEW wherever possible as it saves the amount of external code calls (and believe me, calling ActiveX procedures developed by someone else in Visual Basic is NOT much fun at all...). You can either send the array and other data to the stored procedure (you will find the syntax in the SQL references in LabVIEW help under SQL), or you can send
    the array to the database, and have the database then act upon the array.
    I strongly recommend making routines (subVIs) to handle these operations.
    Sorry I don't have the syntax, I don't have SQL installed on this machine. If you can't find the syntax in the help, please post here again.
    -Mike Du'Lyea

  • How to pass a table as parameter on a stored procedure

    Hello all,
    I want to pass the name of a table as parameter into a stored procedure, that will be used for cursors etc.
    But when i pass the parameter and i compile the S.P. it give me error (error: table not existing...)
    Any Help?
    Thanks in advance, Marco

    Marco wrote:
    As i've written above, i'm using stored procedures like 'batch' programs which will be executed with oracle scheduler (passing to s.p. the name of the 'input' tables)
    These input tables are 'external' tables which have got the same structure; for example i've got TABLEX_001, TABLEX_002, XXTAB etc. with the same structure.
    This is the the reason... what do you think?An external table definition can reference multiple files via the LOCATION definition or you can user "ALTER TABLE" to alter the location and change the file that the external table points to.
    Thus you only need one static External Table and use an alter table (via execute immediate) to change the file location it points to, or if you want all the data together, just specify all the files in the location.
    That would be clean design, using one fixed table, without the need to pass any table names, just dynamically altering the file names if necessary at run time.

  • How to pass the parameter of a stored procedure to iReport

    Hi... i don't know how to pass the parameter of the stored procedure to the iReport.
    In the Report Query, i tried
    1. sp_storedprocedure ' value'
    2. sp_storedprocedure +''''+$P{parameter}+''''+
    3. sp_storedprocedure +$V+$P{parameter}++$F($F is a variable having a value of ' (a single quote))may you enlighten us please? thank you

    For M$ SQL server I find that it only works when U use the fully qualified name...
    e.g. catalod.dbo.my_procedure_name 'variable'
    My full query in the Report Query window is something like this:
    EXEC arc.dbo.jasper_Invoice 1000
    Note that you may find that selecting from VIEWS / TABLES fails for no apparent reason and iReport will prompt you with the usual very unhelpful (we have what we "pay" for) prompt, stating that "The document is empty".
    To work around this issue, where a statement like "SELECT * FROM arc.dbo.acc_invoices WHERE Invoice_id=1000" does not work, simply create a PROC, something like:
    CREATE PROC jasper_MyProc (@my_rec_id integer) AS
    SELECT * FROM arc.dbo.acc_invoices WHERE Invoice_id= @my_rec_id integer
    ...to wrap your SELECT statement, then call the PROC
    Edited by: Sylinsr on Apr 22, 2008 4:23 PM

  • In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String

    In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String , for executing the Stored Procedure with Current date as the input .

    Hi Srinath,
    The below blog might be useful
    http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/06/executing-stored-procedure-from-sender-adapter-in-sap-pi-71
    PI/XI: Sender JDBC adapter for Oracle stored procedures in 5 days
    regards,
    Harish

  • Passing Multi-Value Parameter to a Stored Procedure

    Has anyone experienced passing a Parameter (MultiValue) to a Stored Procedure? I am aware that Crystal Passes the Param as an Array. How would you go about handling this within a Stored Procedure???

    Hi Daniel
    Try as below:
    1. Create a Crystal report, and add a multi-value parameter.
    2. Since the multi-value parameter is treated as an array, create a formula that uses the JOIN function. Create a formula as below:
    //Formula: @JoinFormula
    Join ({?Multi-value parameter array},";")
    ====================
    NOTE:
    In the formula above, a semi-colon (";") is the delimiter.
    ====================
    3. Within the main report, create a subreport based on the stored procedure, and include the parameter to be populated with the multi-value list.
    4. Link the Join formula in the main report to the stored procedure parameter in the subreport.
    Doing so passes a multi-value parameter to the stored procedure.
    Hope this helps!!!!
    Regards
    Sourashree

  • Would like to pass multi-value parameter to a stored procedure

    Hi,
    Is it possible to pass a multi-value parameter to a stored procedure using crystal reports.
    Is there is a way to do so??/
    Thanks,
    Brian.

    Hi,
    Is it that you want to pass 2 or more parameters to a stored proc. it is possible
    go to database expert
    select your connection and click on add command their you will have to create parameters and pass to a proc
    for ref..
    {CALL `menagerie`.`sp_timer`({?delay time},{?delay time2})}
    where `menagerie`.`sp_timer` is a stored proc.
    and delay time and delay time2 are  parameters.
    but if it is like you have to pass multiple values to stored proc using single parameter as per my experience its
    not possible.

  • How to pass parameter from 1 stored procedure to another stored procedure inside crystal report

    Hi
    I have several stored procedure in my Crystal Report. I am wondering if it is possible for me to pass a parameter to one of the stored procedure and to use the result of that stored procedure E.g. CustomerCode. To another 2 stored procedure to generate the report dynamically?
    I have 3 stored procedure
    The 1st one is used to gather information and process the calculation
    another 2 stored procedure is used for generate the graph and both of them required to take 2 parameters. The 1st stored procedure will require 1 parameter (E.G. Reference Code) and will return a set of information including the data that could be use on the other 2 stored procedures.
    After I added these 2 stored procedure, it requires me to pass 3 parameters to the report. I would like to know if I could only pass the Reference Code for stored procedure 1 and use it to retrieve the information for the other 2 parameter?
    Thanks in advance
    Chi

    Hi Chi
    To pass parameter from 1 stored procedure to another stored procedure, you will have to create sub report. In your case you will have to create 2 sub reports for 2nd and 3rd stored procedure and link those sub reports with the main report using Reference Code field in order to pass the values.
    After creating the report when you will refresh the report, it will ask 4 parameters, one parameter for main report, one for the first subreport and two for second subreport to fetch the data correctly.
    Regards
    Poonam Thorat.

  • Problem in OUT Parameter in the stored procedure

    Hi,
    I have a problem in the OUT parameter of the stored procedure under the package. I encountered the error PLS-00306. Below are the codes.
    Package
    CREATE OR REPLACE package body test as
         procedure sp_countries(rst OUT country_typ) as
         sql_stmt VARCHAR2(300);
         begin
         sql_stmt := 'SELECT * FROM countries WHERE region_id = 1';
         OPEN rst FOR sql_stmt;     
         end;
    end test;
    by the way. i declared the country_typ as this:
    TYPE country_typ IS REF CURSOR;
    Here is the code that will call this package:
    declare
    tst countries%ROWTYPE;
    begin
    test.sp_countries(tst);
    dbms_output.put_line(tst.country_name);
    end;

    Works for me. Although I had to use emp instead of your table:
    SQL> create or replace
      2  package test as
      3     TYPE country_typ IS REF CURSOR;
      4     procedure sp_countries(rst OUT country_typ);
      5  end;
      6  /
    Package created.
    SQL> CREATE OR REPLACE
      2  package body test as
      3     procedure sp_countries(rst OUT country_typ) as
      4        sql_stmt VARCHAR2(300);
      5     begin
      6        sql_stmt := 'SELECT * FROM emp WHERE deptno = 20';
      7        OPEN rst FOR sql_stmt;
      8     end;
      9  end test;
    10  /
    Package body created.
    SQL> var tcur refcursor
    SQL> exec test.sp_countries(:tcur);
    PL/SQL procedure successfully completed.
    SQL> print tcur
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
    SQL>

  • Is it possible to pass a null Input Oracle parameter to a stored procedure

    I have a stored procedure that take 3 inputs and gives 1 output.I'm using Oracle parameter to add all 3 input parameters as follows :
    OracleParameter inobj = cmd.Parameters.Add("wid", OracleDbType.Int32,50);
    inobj.Direction = ParameterDirection.Input;
    inobj.Value = _employeeID;
    and added the output parameter as follows:
    OracleParameter outobj = _cmd.Parameters.Add("w_first", OracleDbType.Varchar2, 50);
    outobj.Direction = ParameterDirection.Output;
    On the UI end , the user has a choice to provide 1 input or all inputs or any 2 inputs based on his interest. Stored Proc looks as follows:
    SP( inp1 in parameter, inp2 in parameter, inp3 in parameter, output1 out parameter)
    If i just get 1 input or 2 inputs from the user, is it fine to query the data for output using same stored procedure or should i have individual stored procedures for each scenario(combination of different inputs)?
    Will i get any pl/sql error that says invalid number of arguements?

    This means if i have 1 input , i need to have a different method to pass 1 parameter value and other input parameters as null and if there are 2 inputs will need different method to handle. So 5 different methods all together?
    What if the stored procedure is as follows ,will its make things easier so that only one method is used for all scenarios?(optional parameters is set default value as null in the stored proc)
    Create or Replace
    Procedure GetFoo
    (cur_z OUT sys_refcursor,
    pub_date IN varchar2,
    fname IN varchar2 default null,
    lname IN varchar2 default null,
    phone IN varchar2 default null
    IS
    BEGIN
    ---get some data
    END;
    *actually i can test this but, all the database servers are down today. So, i need to have idea if this thing works before i confirm with someone. Thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • CR XI - Pass a Multi-value Parameter to a Stored Procedure

    Hello,
    Here is my problem !
    My Main Report accept a Multi-value Parameter "myParameter".
    I create a formula "lstParameter" (Join({?myParameter},',')  linked to my SubReport (string static parameter based on a Stored Procedure  which returns a RefCursor (ORACLE)).
    When I launch the Main Report, he is blank...but if I open the subreport in the overview i can see the result...
    it seems like the MainReport don't call the SubReport, or something like that...
    I hope you can help me !
    Thanks
    Anthony
    Edited by: anthony.44 on Jan 12, 2012 4:53 PM
    Edited by: anthony.44 on Jan 13, 2012 9:51 AM

    hello,
    I resolve my problem....just inside into the detail of the Master report a result of a query (ex: select sysdate from dual)...and the sub report is called correctly

  • Parameter type in stored procedure call

    What is the best way using ODP.net to reference the parameter type?
    I have several stored procedure in a Oracle 9i database.
    The database looks like:
    Name Null? Type
    FLTID NOT NULL NUMBER(10)
    PLANEID NOT NULL VARCHAR2(3)
    The call in my VB.net app is:
    cmd = New OracleCommand("AeronauticsUtils.Flights_insert", conn)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.Add(New OracleParameter("fID", OracleDbType.Int32, ParameterDirection.Input)).Value = row("FLTID")
    cmd.Parameters.Add(New OracleParameter("plnid", OracleDbType.Varchar2, ParameterDirection.Input)).Value = row("PLANEID")
    cmd.ExecuteNonQuery()
    cmd.Dispose()
    What should I use?
    OracleDbType.Int32
    OracleType.VarChar
    Types.OracleDecimal
    or something else?

    I use OracleDbType.Decimal for NUMBER columns and OracleDbType.Varchar2 for VARCHAR2 columns.
    Are you having issues?
    - Mark
    ===================================================
    Mark A. Williams
    Oracle DBA
    Author, Professional .NET Oracle Programming
    http://www.apress.com/book/bookDisplay.html?bID=378

  • Does OraOLEDB support passing a Ref Cursor as an IN parameter of a Stored Procedure?

    We have a number of Stored Procedures that take a Cursor as an input parameter. Is it possible to call a Stored Procedure of this type with OraOLEDB? If so could you provide a quick sample using VC++/ATL?
    Thanks...

    Thank you for your reply, Yuancai. It would be very useful if the OLE DB team added such an interface to future versions of TCommand. However, for the time being what is the preferred technique for passing large amounts of data to a stored procedure? For instance we have a number of tables that have fifty or more columns. It would be awkward to call a stored procedure with this many parameters. Ideally, one would want to create a structure as a User Defined Type and pass that as a parameter.
    One approach we though of was to pass a XML string though a CLOB parameter and parse it in either a PL/SQL or Java stored procedure. However, while this approach is novel it is not standard. I've found it best to use standard techniques where possible. Any insight you could give would be appreciated.
    Thanks,
    Bryan Wood

Maybe you are looking for

  • Power View in SharePoint only shows current year.

    I have a customer using the Power View add in for SharePoint 2013 based on SQL 2014.   I have created a BISM object that connects directly to an OLAP cube. When I build reports or Pivot tables against this object they work fine.  However when I build

  • Getting an error in deploying the SalesQuoteDemo application. Pls help.

    As part of my project work, I have to understand BPM/SOA Suite. As part of this, I installed SalesQuoteDemo and all related softwares in my laptop. I have also configured the Weblogic/SalesQuotesDemo as given in the attached PDF documents. Finally, W

  • Sleep & iCal reminders

    I have set my display to go to sleep after an hour of inactivity, but the computer itself is set to never go to sleep. However, iCal does not display reminders if the display is asleep. This means that when I come back to my computer, the reminders h

  • E65 and JRE

    Im using my E65 wireless capability to connect to a piece of equiptment which is WIFI enabled and has an HTTP web server. The pages served from the equipment contain java buttons which the E65 cannot display for some reason. The other content on the

  • Upgrade ipad 2 to iOS 7.1.2

    Hi, I have iPad 2 with iOS 6.1.3 on board. How I can upgrade on iOS 7.1.2 only? Thks