Stored Procedure to check selection of name input box

Hello all,
I have a query with which the user (using Reporting Services) will need to input the last name, and first name, or date of birth, or SSN.  Since the table contains a large amount of data and accessing data from three tables, the process is slow. 
How can I speed up this process?  Is there some way to create a SP to test the different scenarios (i.e., last name and first name, or first name and birthdate, or last name and SSN, etc.)?  To check each scenario that a user may combine will require
a large query.
 In the report, the user will have the option of selecting an employee using (ex. 1 and 2, or 1 and 2 or 3 or 4;   1 or 3;  or 3; or 4) . If I can test this using a SP that would be much easier than having
to duplicate the query for each scenario.  See example below.
Thanks in advance for any assistance given!
declare @lastname varchar (40)
declare @firstname varchar (40)
declare @SSN varchar (11)
declare @birthdate varchar (25)
set @lastname = 'lastname'
set @firstname  ='firstname '
set @SSN ='SSN '
set @birthdate ='birthdate'
(ssn
LIKE '%'
+ @ssn+ '%'
and @lastname=
'' and @birthdate
= '' and @
= '')
OR
(@ssn
= ''
AND lastname LIKE
'%' + @lastname
+ '%' AND @birthdate
= ''
AND @firstname = '')
OR
(@ssn=
'' AND @lastname
= '' AND birthdate
= @birthdate AND @firstname
= '')
OR
(@ssn
= ''
AND @lastname = ''
AND @birthdate =
'' AND firstname
LIKE '%' + @firstname
+ '%')

Well 1st thing... The use of leading wild cards is making your queries non-sargable (can't use indexes) which is a major performance hit.
As far as only searching the applicable table. That's easy enough to control by using IF blocks.
IF @LastName IS NOT NULL AND @FirstName IS NOT NULL BEGIN .... END ELSE IF @LastName IS NOT NULL AND @SSN IS NOT NULL BEGIN .... END ELSE.... and so on.
Jason Long

Similar Messages

  • Can we call a stored procedure in a select statement

    Hi All
    I want to call a stored procedure inside a select statement is this possible.
    Regards
    Sravz

    You can create a pipelined function which gathers the data from your stored procedure and then use that in a select statement or directly write your script in any function or pipelined function. ;)
    There is no way you can call any stored procedure in a SELECT statement directly - i guess.
    Regards.
    Satyaki De.

  • Stored procedure for checking Invoice value if more than R 15 000

    Hi All
    I have a problem with my stored procedure below, i want to check the doctotal if it above R 15 000 , if it is then it checks if the supplier has a tax clearance cert.
    IF @transaction_type = 'A' AND @object_type = '22'
    BEGIN
    If exists (SELECT T0.cardcode, t0.docentry  FROM OPOR T0 where T0.DOCTOTAL >'15,000.00' and T0.U_TAXCLEAR IS NULL AND T0.docentry=@list_of_cols_val_tab_del)
         begin
              SET @error = 10
              SET @error_message = N'Amount is above R 15 000 please select Supplier with Valid Tax Certificate'
    END
    END
    I tried this executing the sp and there was this error
    Msg 208, Level 16, State 6, Procedure SBO_SP_TransactionNotification, Line 41
    Invalid object name 'dbo.SBO_SP_TransactionNotification'.
    In this case line 41 is 2nd END.
    Thanks
    Bongani Dlamini

    Hi all
    Thanks for the replies , forgot to mention a few requirements.
    In addition to the to checking the value above  R 15 000 I want to check if a tax certificate field is populated , if it is then checks if the expiry date is not null.
    please check the query I tried below.
    IF @transaction_type = 'A' AND @object_type = '22'
    BEGIN
        IF EXISTS (SELECT T0.CardCode FROM dbo.OPOR T0
        WHERE T0.DOCTOTAL > 15000 AND T0.U_TAXCLEAR IS NULL AND T0.DocEntry=@list_of_cols_val_tab_del)
        BEGIN
    SET @error = 10
    SET @error_message = 'Amount is above R 15 000, a valid Tax Certificate is required'
    END
    END
    IF @transaction_type = 'A' AND @object_type = '22'
    BEGIN
        IF EXISTS (SELECT T0.CardCode FROM dbo.OPOR T0 WHERE T0.U_EXPIRYDATE IS NULL AND T0.DocEntry=@list_of_cols_val_tab_del)
        BEGIN
    SET @error = 10
    SET @error_message = 'Tax Certificate expiry date is required'
    END
    END
    Thanks
    Bongani Dlamini

  • Stored Procedure for checking Invoice Vendor ref No

    Hi All
    I need a sp for checking a vendor ref no  on an invoice if it already exist in the system or the user forgot to include one when trying to add the document.
    I get this error on the one that I created
    16/03/2010  12:21:54: [Microsoft][SQL Native Client][SQL Server]Conversion failed when converting the nvarchar value '24     0' to data type int. (CINF)
    Here is my SP :-
    DECLARE @Invoice AS VARCHAR(15)
    DECLARE @Card AS VarChar (20)
    SELECT @invoice = NumatCard, @card = CardCode FROM dbo.OPCH
    WHERE DocEntry = @list_of_cols_val_tab_del
    if @object_type = '18' and @transaction_type in (N'A', N'U') -- AP Invoice is null
    begin
        If exists (SELECT T0.cardcode, T0.NumAtCard  FROM OPCH T0 where T0.NumatCard is null and  T0.cardcode=@list_of_cols_val_tab_del)
         begin
              SET @error = 10
              SET @error_message = N'Supplier invoice number not entered.'
         END
    END
    SELECT @INVOICE = NumatCard FROM dbo.OPCH
    WHERE DocEntry = @list_of_cols_val_tab_del
    if @object_type = '18' and @transaction_type in (N'A', N'U') -- AP Invoice to check if the invoice no exist
    begin
        If exists (SELECT T0.cardcode, T0.NumatCard  FROM OPCH T0 where T0.NumatCard = @invoice  and  T0.cardcode=@list_of_cols_val_tab_del)
         begin
              SET @error = 10
              SET @error_message = N'This invoice number already exist for this supplier.'
         END
    END
    Regards
    Bongani Dlamini

    This code should be inserted into the original (or already expanded) SBO_SP_TransactionNotification stored procedure after the line
    --     ADD     YOUR     CODE     HERE )
    Try this full (and a little modified) procedure:
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER proc [dbo].[SBO_SP_TransactionNotification]
    @object_type nvarchar(20),                     -- SBO Object Type
    @transaction_type nchar(1),               -- [A]dd, <u>pdate, [D]elete, [C]ancel, C[L]ose
    @num_of_cols_in_key int,
    @list_of_key_cols_tab_del nvarchar(255),
    @list_of_cols_val_tab_del nvarchar(255)
    AS
    begin
    -- Return values
    declare @error  int                    -- Result (0 for no error)
    declare @error_message nvarchar (200)           -- Error string to be displayed
    select @error = 0
    select @error_message = N'Ok'
    --     ADD     YOUR     CODE     HERE
    if @object_type = '18' and @transaction_type in (N'A', N'U') -- AP invoice
    BEGIN          ----
    DECLARE @Invoice AS VARCHAR(15)
    DECLARE @Card AS VarChar (20)
    SELECT @invoice = NumatCard, @card = CardCode FROM dbo.OPCH
         WHERE DocEntry = @list_of_cols_val_tab_del
    -- AP Invoice is null
    If exists (SELECT T0.cardcode, T0.NumAtCard FROM OPCH T0 where T0.NumatCard is null
               and T0.DocEntry=@list_of_cols_val_tab_del)
    begin
    SET @error = 10
    SET @error_message = N'Supplier invoice number not entered.'
    end
    -- AP Invoice to check if the invoice no exist
    If exists (SELECT T0.cardcode, T0.NumatCard FROM OPCH T0 where T0.NumatCard = @invoice
               and T0.CardCode=@card and T0.DocEntry!=@list_of_cols_val_tab_del)
    begin
    SET @error = 10
    SET @error_message = N'This invoice number already exist for this supplier.'
    end
    END          ----
    -- Select the return values
    select @error, @error_message
    end

  • Problem calling stored procedure with user-defined type of input parameters

    Hi,
    I have to call a stored procedure with IN parameters, but these are user-defined types of input parameters.
    function fv_createnews (
    pit_groups in T_APPLICATION_USER_GROUPS,
    pit_documents in T_DOCUMENTS
    return varchar2;
    TYPE T_APPLICATION_USER_GROUPS IS
    TABLE OF varchar2(500)
    INDEX BY binary_integer;
    TYPE T_DOCUMENT IS record (
    name varchar2(256)
    ,url varchar2(1024)
    ,lang varchar2(30)
    ,foldername varchar2(150)
    TYPE T_DOCUMENTS IS
    TABLE OF T_DOCUMENT
    INDEX BY binary_integer;
    How can I do this using the TopLink 10.1.3 API.
    I already found following related posts, but I still can' t make it up:
    Using VARRAYs as parameters to a Stored Procedure
    Pass Object as In/Out Parameter in Stored Procedure
    Or do I have to create my own PreparedStatement for this special stored procedure call using Java and Toplink?

    As the related posts suggest, you will need to use direct JDBC code for this.
    Also I'm not sure JDBC supports the RECORD type, so you may need to wrap your stored functions with ones that either flatten the record out, or take OBJECT types.

  • Calling Stored Procedure(takes varray of objects as input) from jdeveloper

    How can i call Stored Procedure which takes varray of objects as input from jdeveloper
    My object is :
    TYPE Entry IS Object (
    Name VARCHAR2(1024),
    Value VARCHAR2(1024)
    & the varray is :
    TYPE EntryArr IS varray(10) OF Entry ;
    & the procedure is :
    PROCEDURE myProc( myEntryArr IN EntryArr )
    AS
    s varchar2(1024);
    BEGIN
    for i in 1.. myEntryArr .COUNT loop
    if myEntryArr(i).Name = 'Name1' then
    s := myEntryArr(i).Value
    end loop;
    end;

    hi 429071
    Maybe you can find some useful information in:
    "Oracle Database Java Developer's Guide"
    http://download-west.oracle.com/docs/cd/B14117_01/java.101/b12021.pdf
    see "6 Publishing Java Classes With Call Specs" > "Writing Object Type Call Specs"
    success
    Jan Vervecken

  • Oracle function in stored procedure to retreive particular table name

    Hi,
    I need to delete a table 'xxsys_dram_flatproperties' from database given model name as 'dram-model'.
    the model name can be any thing.corresponding table name will be[i] 'xxsys_<modelname>_flatproperties'.
    I wrote stored procedure .I am able to retrieve all the tables in the database using user_tables.Is there any funtion in oracle like
    if table name contains letters that are there in model name.
    Pleasehelp.

    Suppose all your tables created in the schema 'temp'
    and you are absolutly sure you want to drop only tables which have for example '_model3_' in its name (nothing else should have same part in your schema)
    then try a simple solution:
    CREATE TABLE temp.xx_model3_01 (col1 NUMBER)
    CREATE TABLE temp.xx_model3_02 (col1 NUMBER)
    SELECT table_name from all_tables where OWNER = 'TEMP' and table_name LIKE '%_MODEL3_%'
    TABLE_NAME                   
    XX_MODEL3_01                 
    XX_MODEL3_02
    DECLARE
       CURSOR c1
       IS
          (SELECT table_name
             FROM all_tables
            WHERE owner = 'TEMP' AND table_name LIKE '%_MODEL3_%');
    BEGIN
       FOR rec IN c1
       LOOP
          EXECUTE IMMEDIATE 'DROP TABLE ' || rec.table_name;
       END LOOP;
    END;

  • Can we get data return from stored procedure in a select query ?

    Hello,
    Suppose i have a function GetSum(x,y) that returns sum of two numbers x and y .We can call this function from within a sql function like this :
    select GetSum(4,5) SUM from dual;But is this possible through a stored procedure ? i.e., can i call a stored procedure from within a select query like i have done in above code ?

    Hi,
    bootstrap wrote:
    Hello,
    Suppose i have a function GetSum(x,y) that returns sum of two numbers x and y .We can call this function from within a sql function like this :
    select GetSum(4,5) SUM from dual;But is this possible through a stored procedure ? i.e., can i call a stored procedure from within a select query like i have done in above code ?The short answer has already been given.
    Why can't you use a function?
    Suppose you could use a procedure. What results would you want to see from:
    SELECT  my_proc (4, 5)
    FROM    dual
    ;? Why?
    Explain what you want to do, and somebody will help you find a good way to do it.

  • Use of a stored procedure in a select statement submitted to cx_oracle

    Hi,
    I am developping under python and I'm using the cx_oracle interface.
    I've written a stored procedure that I've tested directly under sqlplus session : it's ok. I've also tested this stored procedure from python by using callproc routine : its also ok.
    Now I need to use this procedure within a select statement that I submit to the execute statement of cx_oracle as :
    s = "select a.airport_name,gmlpos.ExpLatLong(a.point_name) from airport"
    self.db = oracledb('ops/opeope00@ACE2008B')
    dbmsg = self.db.execute(s)
    IF (dbmsg == "") :
    An error occurs :
    Message = request = select a.AIRPORT_NAME, gmlpos.ExpLatLong(a.point_name) from airport, errmsg = ORA-00904: "GMLPOS"."EXPLATLONG": invalid identifier
    Noting that the execution of any other select (without stored procedure) order from python works fine.
    Is anybody has a solution or workaround ?
    thanks a lot for your help

    The result gives what is expected :
    AIRP
    GMLPOS.EXPLATLONG(A.POINT_NAME)
    LFLL
    -45.71666666666667 -5.08333333333333
    As I said the stored procedure works fine.
    Thanks for your expertise
    PS : why change the login password until nobody says which machine or database is concerned ?

  • Calling a stored procedure with argument as column name

    hi
    i am calling a stored procedure mapping_audit_errors_inserts
    whose definition is as follows
    PROCEDURE mapping_audit_errors_inserts (
    in_ma_seq_id IN ETL_MAPPING_AUDIT_ERRORS.ma_seq_id%TYPE,
    in_etl_stage IN ETL_MAPPING_AUDIT_ERRORS.etl_stage%TYPE,
    in_sqlerrcode IN ETL_MAPPING_AUDIT_ERRORS.sqlerrcode%TYPE
    IS
    BEGIN
    mapping_audit_ora_errors (in_ma_seq_id,
    in_etl_stage,
    in_sqlerrcode,
    get_error_message (in_sqlerrcode)
    END;
    now i need to call this procedure as
    mapping_audit_errors_inserts(MA_SEQ_ID.currval,1,v_error_code)
    [ v_error_code:=SQLCODE;]
    it is giving error as
    PLS-00201: identifier 'MA_SEQ_ID.CURRVAL' must be declared
    can anyone calrify me on this.
    Thanks

    Anwar is likely correct about the reason for your error. The other possibility is that the owner of the procedure calling mapping_audit_errors_inserts does not have SELECT on the sequence granted directly to them.
    However, even after creating the sequence, if the session calling the procedure has not got a value from the sequence prior to trying to use CURRVAL, you will get:
    SQL> CREATE PROCEDURE p(p_id IN NUMBER) AS
      2  BEGIN
      3     DBMS_OUTPUT.Put_Line('ID is '||p_id);
      4  END;
      5  /
    Procedure created.
    SQL> DECLARE
      2     l_no NUMBER;
      3  BEGIN
      4     SELECT ma_seq_id.CURRVAL INTO l_no
      5     FROM dual;
      6     p(l_no);
      7  END;
      8  /
    DECLARE
    ERROR at line 1:
    ORA-08002: sequence MA_SEQ_ID.CURRVAL is not yet defined in this session
    ORA-06512: at line 4And, just to reinforce Anwar's point about selecting it into a variable, if you try to pass CURRVAL to a procedure, you will get:
    SQL> DECLARE
      2     l_no NUMBER;
      3  BEGIN
      4     SELECT ma_seq_id.NEXTVAL INTO l_no
      5     FROM dual;
      6     p(ma_seq_id.CURRVAL);
      7  END;
      8  /
       p(ma_seq_id.CURRVAL);
    ERROR at line 6:
    ORA-06550: line 6, column 16:
    PLS-00357: Table,View Or Sequence reference 'MA_SEQ_ID.CURRVAL' not allowed in
    this context
    ORA-06550: line 6, column 4:
    PL/SQL: Statement ignoredTTFN
    John

  • Executing a stored procedure containing multiple Select statements

    Post Author: Beverly
    CA Forum: General
    I am using Crystal  10.0 against a MS SQL 2000 server.
    I am trying to create a report based on a stored procedure that contains multiple select statements.  The sp requires a single parameter (Claim number) and contains 17 Select statements that produce results.
    I am able to use the Add command and execute the sp with the parameter, but I am only getting the results of the first select statement in the sp back in my data set.  Is there a way to have the data from each Select statement returned to my report?
    I have used Crystal for a while, but pretty much for straight-forward reporting.  I am familiar with the basics of SQL.
    I would appreciate any help anyone can offer.
    Thanks.

    Post Author: BISoftware
    CA Forum: General
    I believe Crystal Reports can only handle one recordset at a time, which means it can only handle a single select statement.  The only way I can see around this would be to break up your stored procedure into multiple stored procedures, so that each only contains a single select statement.  Then, use subreports to report on each individual sp. Hope this helps. - Davewww.BusinessSoftwareResource.com

  • Stored Procedure in access with parameter name

    Hi, i'm new in JDBC.
    I came from Ado.Net.
    I want to call a stored procedure in access and set my parameters by name and not by index.
    When i try to call the SP with params by index it works as expected,
    but with param names it give me this exception:
    java.lang.UnsupportedOperationException
    Is there a way to call SP with parameter names?
    BogN,

    Well, it still doesn't work. Here is part of the code, have a look please.
    public DisplayQueryResults() {
       String studattUrl = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:/StudAtt/StudAtt.mdb";
       String mustbUrl = "jdbc:odbc:mustb";          
       try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          studattConn = DriverManager.getConnection(studattUrl);
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          mustbConn = DriverManager.getConnection(mustbUrl, "sa", "");               
    private void getTable() {
       try {
          stmtStudAtt = studattConn.createStatement(resultSet.TYPE_SCROLL_SENSITIVE, resultSet.CONCUR_READ_ONLY);
          stmtMustb = mustbConn.createStatement();
          CallableStatement callSP = studattConn.prepareCall("{call mustbFaculty}");
          resultSet = callSP.executeQuery();
          displayResultSet(resultSet);
       }

  • Pl/sql stored procedure code2 check the emial id is correct or not

    if the mail id is [email protected]@.com
    then how we do validations means
    there must be only one @
    i wnat all tghis type of validations 2 check the email id is correct or not?
    the procedure that i wnat to validate akll the validations

    This appears to be a duplicate of your existing thread
    pl/sql stored procedure for email id validations
    I'll answer there.
    Justin

  • Calling Stored Procedure with a different user name

    Hi,
    I am in the process of converting OracleClient based .NET 2.0 application to ODP.NET
    and while trying to replace an existing call to a stored procedure which is in another user schema(different user)
    the ORACLE Client(Microsoft) version worked fine with the following calling mechanism -
    USERNAME.PACKAGENAME.STOREDPROCEDURENAME
    Example : objCmd.CommandText ="*USERNAME*.*PACKAGENAME*.*STOREDPROCEDURENAME*"
    and it does not work when used with ODP.NET.
    I tried using-
    "@USERNAME.PACKAGENAME.STOREDPROCEDURENAME"
    still it does not work.
    Any help is appreciated?
    Thanks...!!
    Edited by: user4553639 on Mar 16, 2011 1:09 PM
    Got it resolved....had to change the Package. No code change needed on the .NET side.
    Edited by: user4553639 on Mar 17, 2011 1:08 PM

    Got it solved.

  • Displaying data from stored procedure into textbox fields based on user input.

    I have a stored procedure that is selecting data from a table called "Vendor" in my database.  The data that is being returned are vendor names, vendor addresses, vendor Id's, etc...In my stored proc, I have one parameter that allows
    the user to enter a vendor name and then return all the data for that specific vendor.  The report that I'm building is going to look like a basic form with a bunch of textboxes on the screen labeled Vendor Address, Vendor Id, Vendor City, Vendor State,
    etc...In the report I'm trying to build, the user will enter in a vendor name and then it will return all of the vendor's data based on what the user searches for.  However, the report will only return ONE vendor's data at a time. 
    The problem is that some of the data in the database has very similiar vendor names, but different vendor addresses, vendor Id's, etc...In some instances the vendor name is actually
    exactly the same, but the vendor address, vendor city, vendor Id, is all different.  So what I did was added another parameter in my report that shows a drop down list of vendor names based on the wildcard search the user just did and
    allows the user to select the exact vendor name that he/she is looking for based on what they searched.  The problem I'm having is that I don't know what expression I need to put in each one of my textboxes to retrieve the correct data from
    the vendor table that the user selects from the drop down list.  So what I want to do is return the exact data from the vendor table based on the selection that the user makes from that drop down list.  It's like I somehow have to compare the
    drop down list parameter directly to the dataset but I don't know what expression needs to go in the textbox.  I've tried...=First(Fields!VendorName.Value, "DataSet1").EqualsParameters!DropDownList.Value(0) but I keep getting an error message.
    --Here is an example of the kind of thing the user might search for...when the user searches the word "sprint" it returns three different vendor names to the drop down list.
    1. sprint
    2. sprint
    3. sprint co
    Each one of those three vendor names has a different vendor address, vendor city, vendor ID, etc...but the vendor names are extremely similar and in some cases
    exactly the same. In my report now I can't get the textboxes to return the correct data based on what the user selects.  Any advice at all is greatly appreciated.
    P.S. I didn't even know what SQL Server was a month ago and had zero knowledge of SSRS at all.  I've learned a lot recently, but if you could explain a solution in the easiest way possible I would appreciate it. Thanks!

    Hi Jrcowles,
    If I understand you correctly, you wnat to list all the Vendor Name which like the user typed Vendor Name on a drop-down list, right? If in this case, we can use a cascading parameters to achieve your requirement. I have tested it on my local environment,
    the steps below are for you reference.
    Create an other stored procedure using the query below.
    CREATE PROCEDURE GetVendorName
    @VendorName NVARCHAR(50)
    AS BEGIN
    exec( 'SELECT * FROM Vendor WHERE VendorName LIKE ''%'+@VendorName+'%''')
    END
    Create another dataset DataSet2 and using the new created procedure.
    Create another parameter VendorName2 and check "Allow Multiple Values" for this parameter.
    On the Available Values tab, check "Get values from a query". Select corresponding dataset and field.
    On the Default Values tab, check "Get values from a query". Select corresponding dataset and field.
    The screenshots below are for you reference.
    Reference
    http://technet.microsoft.com/en-us/library/aa337169(v=sql.100).aspx
    http://www.msbiguide.com/2012/02/adding-cascading-parameters-to-ssrs-reports/
    Regards,
    Charlie Liao
    TechNet Community Support

Maybe you are looking for

  • Cannot establish secure connection to account--trying again

    When I try to get to the itunes store from itunes, I get a message saying that Apple cannot establish a secure connection. It suggests checking to see that my browser has SSL3.0 or TLS 1.0 enabled. I have both of those protocols enabled, and always h

  • SESSION AND SPID.

    Hi, guys. Does one session always have one spid? I quried. SELECT S.SID, S.SERIAL#, S.SUSERNAME, P.SPID FROM (SELECT SID, SERAIL#, USERNAME, PADDR FROM V$SESSION WHERE USERNAME = 'AAA') S, (SELECT ADDR, UPPER(USERNAME) FROM V$PROCESS WHERE USERNAME =

  • Unit tests - log4j

    Hi, I am using log4j and this is a fragment from my log4j.properties file: log4j.appender.gen.file=${catalina.home}/logs/foo.logWhen the container is up, ${catalina.home} is interpreted to the correct path. How about when running unit tests though? I

  • IPhone 5S shared photostream green border

    I have an iPhone 5S, running iOS 7.0.2. When I add a picture to a shared photostream through the photos app, from the camera roll, it sometimes makes the image one pixel wider and taller, and adds a green line to the bottom and right side. The same p

  • Query FI - coding for including fields from doc and clearing doc

    Hi! I am a functional FI consultant and need to create a query (SQ01) with information from the payment document and the invoice which was cleared by the payment. I need to know which coding to use to include two fields from the invoice document in t