T-sql 2012 accept null parameter values

The following t-sql 2012 works fine in sql management studio. However when I place it in a .net 2010 web form application, I am told the sql does not work when the parameter values are null. Thus can you tell me what I can change in the sql below that will
accept null as 3 possible input values?
SELECT i.[lastName]
            ,i.[firstName] 
            ,i.[middleName]
            ,i.[suffix] 
            ,a.[userid]
            ,a.schoolnum 
            ,a.spa 
            ,a.mrref
            from [OPS].[dbo].[Identity] i 
            inner join  [OPS].[dbo].[Person] p on i.identityID = p.currentIdentityID 
            inner join [OPS].[dbo].[UserAccount] u on u.personID = p.personID 
            inner join [CampusOps].[dbo].[AtnLtrUsers] a on a.userid =u.username
                   where (i.[lastName] like  '%' + @lname  + '%' or i.[firstName] like'%' +
@fname + '%'
                   or i.[middleName]  like'%' + @mname + '%')
or (@fname is null and @lname is null and @mname is null)
        order by  i.[lastName], i.[firstName], i.[middleName]"

You should create a stored procedure for this.
create procedure GetNames
(@lname varchar(max) = null, @fname varchar(max) = null, @mname varchar(max) = null)
as
begin
SELECT i.[lastName]
,i.[firstName]
,i.[middleName]
,i.[suffix]
,a.[userid]
,a.schoolnum
,a.spa
,a.mrref
from [OPS].[dbo].[Identity] i
inner join [OPS].[dbo].[Person] p on i.identityID = p.currentIdentityID
inner join [OPS].[dbo].[UserAccount] u on u.personID = p.personID
inner join [CampusOps].[dbo].[AtnLtrUsers] a on a.userid =u.username
where (i.[lastName] like '%' + @lname + '%' or @lname is null) and
(i.[firstName] like'%' + @fname + '%' or @fname is null) and
(i.[middleName] like'%' + @mname + '%' or @mname is null)
order by i.[lastName], i.[firstName], i.[middleName]
end
Also keep in mind that NULL is different than an empty string but it should work exactly like a null anyway (unless your columns/fields are also NULLable).

Similar Messages

  • Crystal Reports 9 and SQL Server 2005 default parameter values

    We're using Crystal Reports 9 and upgraded from SQL Server 2000 to SQL Server 2005.
    I'm noticing a very weird problem which I wonder if anyone else has experienced (and hopefully found a resolution for). It appears that in using Crystal with SQL Server 2005 stored procedures, if we have default parameter values in the stored procedures, the default parameter values get completely ignored if you pass in a NULL value from Crystal!
    For example, if you have a stored procedure that begins like this:
    ALTER          Procedure [dbo].[StoredProcedure]
    @Param1 VarChar(200) = '',
    @Param2 VarChar(200) = ''
    AS ...
    both @Param1 and @Param2 have a default value of an empty string, and therefore should become empty strings if nothing (NULL values) gets passed in for them.
    But, like I said, what I'm finding is that with Crystal calling the stored procedure with NULL @Param1 and @Param2 values, they never become empty strings, but rather remain as NULLs.
    This was never a problem with SQL 2000.
    Very perplexing. Anyone else every experience this?
    Thank you.

    Please ignore my earlier post -- answered my own question.
    NULL parameter values do not get replaced by default values in SQL -- that is normal behavior in both SQL 2000 and SQL 2005. Just goes to show, that no many how many years programming experience you have, you can still get tripped up sometimes : (

  • SQL 2012: change startup parameter without GUI

    I would like change SQL startup parameter like -l, -d,-e without using SQL Server Configuration Manager. I want to use command line...how can I do it ?

    If its SQL server 2008 R2 SP2 and higher we have DMV(dm_server_registry). As the Registry holds the startup parameters can be different for different
    instances using dm_server_registry DMV will return the correct path for startup parameters.
    select * from sys.dm_server_registry where value_name like 'SQLArg%'
    SQLArg0 identifies the master db data file.
    SQLArg1 identifies the Errorlog folder.
    SQLArg2 identifies the master db log file.
    xp_regwrite to change startup parameter.

  • VO query with SQL table function (MS SQL) and update of parameter value

    Hello All,
    I use VO where Query is the SQL function that returns a table (MS SQL Server):
    select * from getData('XXXX')
    where ‘ХХХХ’ should be binded to the specific ID (e.g. selected row in the tree view on the another facet).
    More details: I have two facets. Left facet contains a tree view that displays the list of the projects grouped by industry. Right facet contains a pivot table (source query is a ‘table function’ from above).
    I want to have the pivot table (right facet) to be updated with the data specific to the project (selected row in the tree).
    I know about the possibility to dynamically update the where clause (setNamedWhereClauseParam method), but in my case there is no ‘where’ clause. Is there any kind of ‘bind variable’ to be used to refresh the data?
    Any guidance, ideas, examples are greatly welcome.
    With best wishes,
    Anatol

    Are the columns that are being selected different each time or the same?
    If they are the same then you don't need to do any additional binding - the pivot table is connected to the VO at design time and it wouldn't care if the underlying from/where have changed.
    If on the other hand your columns change (but the number of them stay the same) then use aliases for the initial definition (select ename a, id b, salary c) and then when you change the VO change the mapping but keep the names (select dname a, moo b, foo c).
    If the whole query is changing and you don't know in advance the structure - then there is no out of the box solution with a pivot table - you'll need to code a backing bean that will provide the data model to the pivot table based on your query.

  • Multiple selection of parameter values (BIP 10.1.3.2)

    Hi there,
    I'm working with BI Publisher 10.1.3.2 and I'd like to use parameters allowing multiple selection. I've tried it with both data templates and SQL queries ... but I'm not getting it work ...
    I've established a simple "Show me department name and id"-example according to my parameter selection (you can select multiple values e.g. Administration, Marketing, Sales ... and the "All"-option is activated as well), based on the HR/OE schema.
    Here's just a quick note, where I tested the way the Publisher Engine copes with parameter selection in general
    5.6.2
    single selection => e.g. Administration
    multiple selection => e.g. Administration,Marketing
    All => *
    10.1.3.2
    single selection => e.g. Administration
    multiple selection => e.g. 'Administration','Marketing'
    All => null
    So, in 10.1.3.2 there's been an improvement concerning single quotes - in the case of multiple selection only. I do not know why there are no single quotes for a single selection, but it seems like that's the way it is ...
    Well, I've created a simple SQL query as follows:
    CASE 1 *
    select DEPARTMENT_ID as ID, DEPARTMENT_NAME as NAME
    from DEPARTMENTS
    where DEPARTMENT_NAME IN (:myParameter)
    => All does not work
    => Single Selection is working
    => Multiple Selection is working
    sample output in the case of selecting "Marketing" (single selection):
    <TESTINGIN>
    <myParameter>Marketing</myParameter>
    <LIST_DEPTS>
    <DEPTS>
    <_MYPARAMETER>Marketing</_MYPARAMETER>
    <ID>20</ID>
    <NAME>Marketing</NAME>
    </DEPTS>
    </LIST_DEPTS>
    </TESTINGIN>
    ... and I've tried the same select statement using a data template instead, and then I got another result: both, All and Multiple Selection, do not work (I'm getting back an empty element)
    sample (error) output in the case of selecting both "Marketing" and "Administration" (multiple selection):
    <TESTINGIN>
    <myParameter>'Administration','Marketing'</myParameter>
    <LIST_DEPTS></LIST_DEPTS>
    </TESTINGIN>
    In order to cover the "All"-case ... I manipulated my select statement as follows and used it as SQL query:
    CASE 2 *
    select DEPARTMENT_ID as ID, DEPARTMENT_NAME as NAME
    from DEPARTMENTS
    where DEPARTMENT_NAME IN (nvl(:myParameter, DEPARTMENT_NAME))
    => All is working now
    => Singe selection is working
    => Multiple selection is not working any more (ORA-00909: Ungültige Anzahl von Argumenten / illegal amount of arguments)
    ... using the same select statement within a data template, Multiple Selection is still not working (empty element)
    Last, I've tried another select statement, based on an entry of the xml publisher forum:
    CASE 3 *
    select DEPARTMENT_ID as ID, DEPARTMENT_NAME as NAME
    from DEPARTMENTS
    where DEPARTMENT_NAME IN (:myParameter) or :myParameter IS NULL
    => All is working
    => Singe selection is working
    => Multiple selection is not working (ORA-00920: Ungültiger relationaler Operator / illegal relational operator)
    So, I couldn't find a way that all three possibilities are working ... and using data templates, multiple selection never worked. If I hardcoded the where clause in the data template,
    e.g. where DEPARTMENT_NAME IN ('Administration','Marketing'), it worked fine (no matter, whether I place the sql statement within an CDATA section, or not).
    Can anyone tell me, what I'm doing wrong here?
    While testing my problem, I figured out that there's a difference of generated parameter output ... I just put the parameter in the select list, and depending on whether you use SQL query or data template, you'll get different results:
    SQL statement
    => for each parameter value an own parameter
    <_MYPARAMETER>Administration</_MYPARAMETER> in the case of single selection
    <_MYPARAMETER8093>Administration</_MYPARAMETER8093>
    <_MYPARAMETER8094>Marketing</_MYPARAMETER8094> in the case of multiple selection
    data Template
    => list of parameter values
    <_MYPARAMETER>Administration</_MYPARAMETER> in the case of single selection
    <_MYPARAMETER>'Administration','Marketing'</_MYPARAMETER> in the case of multiple selection
    Maybe that's the problem? I don't know, this difference how the Publisher Engine copes with parameters just attracted attention to me ...
    Alright, I hope it was not too confusing. I would appreciate any help, since here @ the customer's site we need to use data templates inclduing multiple selection in order to establish a context for VPD.
    The problems in summary:
    - how to write a select statement to include all three possibilites of parameter selection (single selection, multiple selection, All option)
    - multiple selection never worked using data templates
    Can someone help me here?

    hi,
    i think you have to use lexical parameters and a package, like this:
    <dataTemplate name="departments" dataSourceRef="hr@demo" defaultPackage="bip_departments">
    <parameters>
    <parameter name="p_location_id" include_in_output="false" datatype="float"/>
    </parameters>
    <dataTrigger name="beforeReport" source="bip_departments.beforeReportTrigger"/>
    <dataQuery>
    <sqlStatement name="Q1">
    <![CDATA[ select d.department_id, d.department_name, d.location_id
                      from departments d
                     &p_where_clause
                order by location_id, department_id]]>
    </sqlStatement>
    </dataQuery>
    <dataStructure>
    <group name="LOC" source="Q1">
    <element name="location_id" value="location_id"/>
    <group name="DEPT" source="Q1">
    <element name="department_id" value="department_id"/>
    <element name="department_name" value="department_name"/>
    </group>
    </group>
    </dataStructure>
    </dataTemplate>
    with package:
    create or replace package bip_departments
    as
    p_location_id long;
    p_where_clause long;
    function beforereporttrigger
    return boolean;
    end bip_departments;
    create or replace package body bip_departments
    as
    function beforereporttrigger
    return boolean
    is
    l_return boolean := true;
    begin
    if (p_location_id is not null)
    then
    p_where_clause := 'where (d.location_id in (' || replace (p_location_id, '''') || '))';
    else
    p_where_clause := 'where 1=1';
    end if;
    return (l_return);
    end beforereporttrigger;
    end bip_departments;

  • How to capture a parameter value in SQL QUERY of scale marker using GO URL

    Hi,
    Can any one please tell me how to capture the parameter value from go url inside Where clause of Scale Marker.
    I am trying to sift the position of scale marker based on SQL Query.
    Thanks-Bhaskar Gouda.
    Edited by: 961171 on Sep 25, 2012 12:33 AM

    Since this is a synchronous interface, where source is a soap(proxy) call and target is JDBC in the first mapping both of them are request scenarios.
    Source Structure:
    RootNode
        Request             1...unbounded
           No_of_Days   1.1 String
    Target Structure:
    RootNode
       Statement
         TableName
             Action mapped to SQL_QUERY
            Access -  SELECT DISTINCT AL.EC_NO,DP.DATE_TO_FORMAL FROM T_APPLICATION_LIST AL,(SELECT DE.EC_NO AS "EC_NO", DE.PACKAGE_NO AS "PACKAGE_NO",PC.DATE_TO_FORMAL AS "DATE_TO_FORMAL" FROM DAICYO_ECNO DE,PACKAGECTL PC WHERE DE.PACKAGE_NO = PC.PACKAGE_NO AND PC.DATE_TO_FORMAL > (TRUNC(SYSDATE) - to_number('$No_Of_DAYS$'))) DP WHERE AL.EC_NO IN  (SELECT EC_NO FROM DAICYO_ECNO WHERE PACKAGE_NO IN (SELECT PACKAGE_NO FROM PACKAGECTL WHERE DATE_TO_FORMAL > (TRUNC(SYSDATE) - to_number('$No_Of_DAYS$')))) AND (AL.FAMILY = ''  or  '' is null and AL.FAMILY is not null ) and DP.EC_NO = AL.EC_NO ORDER BY DATE_TO_FORMAL
         Key
          No_Of_Days   1..1 String
    In Return I am expecting a JDBC response from the Oracle Database as:
    Source Structure:
    RootNode
      STATEMENT_response   1...unbounded
         row                               0...undbounded
           EC_NO                        1..1   String
    Target Structure:
    RootNode
      RESPONSE
        row
         EC_NO                     1..1     String

  • Unable to capture the parameter values from a PL/SQL procedure

    hi.
    i'm trying to capture the parameter values of a PL/SQL procedure by calling inside a anonymous block but i'm getting a "reference to uninitialized collection error" ORA-06531.
    Please help me regarding.
    i'm using following block for calling the procedure.
    declare
    err_cd varchar2(1000);
    err_txt VARCHAR2(5000);
    no_of_recs number;
    out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
    cntr_var number:=0;
    begin
         rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
         dbms_output.put_line('The error is ' ||err_cd);
         dbms_output.put_line('The error is ' ||err_txt);
         dbms_output.put_line('The cntr is ' ||cntr_var);
         for incr in 1 .. OUT_SIGN_TAB.count
         loop
         cntr_var := cntr_var + 1 ;
    Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN_TAB(incr).txn_type||','||OUT_SIGN_TAB(incr).objid);
    end loop;
    end;
    Error is thrown on "for incr in 1 .. OUT_SIGN_TAB.count" this line
    Following is some related information.
    the 3rd parameter of the procedure is a out parameter. it is a type of a PL/SQL table (SEARCH_SIGN_TAB_TYPE) which is available in database as follows.
    TYPE "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
    TYPE "SEARCH_SIGN_TYPE" AS OBJECT
    (ref_no VARCHAR2(22),
    ciref_no VARCHAR2(352),
    ac_no VARCHAR2(22),
    txn_type VARCHAR2(301),
    objid VARCHAR2(1024))............

    We don't have your rt843pq procedure, but when commenting that line out, everything works:
    SQL> create TYPE "SEARCH_SIGN_TYPE" AS OBJECT
      2  (ref_no VARCHAR2(22),
      3  ciref_no VARCHAR2(352),
      4  ac_no VARCHAR2(22),
      5  txn_type VARCHAR2(301),
      6  objid VARCHAR2(1024))
      7  /
    Type is aangemaakt.
    SQL> create type "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
      2  /
    Type is aangemaakt.
    SQL> declare
      2    err_cd varchar2(1000);
      3    err_txt VARCHAR2(5000);
      4    no_of_recs number;
      5    out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
      6    cntr_var number:=0;
      7  begin
      8    -- rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
      9    dbms_output.put_line('The error is ' ||err_cd);
    10    dbms_output.put_line('The error is ' ||err_txt);
    11    dbms_output.put_line('The cntr is ' ||cntr_var);
    12    for incr in 1 .. OUT_SIGN_TAB.count
    13    loop
    14      cntr_var := cntr_var + 1 ;
    15      Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN
    TAB(incr).txntype||','||OUT_SIGN_TAB(incr).objid);
    16    end loop;
    17  end;
    18  /
    The error is
    The error is
    The cntr is 0
    PL/SQL-procedure is geslaagd.Regards,
    Rob.

  • Error occurred in deployment step 'add solution' value cannot be null Parameter name: g

    Hi!
    I have a SharePoint Server 2013 with latest updates. Worflow Manager 1.0 installed and configured correctly. The server has a website, site temblate is Reacods Center. This site is default. On the site I created a blank Document library "TestLib"
     If I create workflow in SharePoint Designer 2013, workflow works normally. Workflow set Title of element to "MyCustomTitle" and Write to History string "Done!".
    If I create Empty Solution in Visual Studio 2013, insert into solution Workflow and make same actions, my solution at deployment step fails with error:
    "error occurred in deployment step 'add solution' value cannot be null Parameter name: g"
    Please, help me to resolve this problem?
    Thanks!

    Hi,
    What if stop this service, then start it again, perform an iisreset? It will make the change applied to the whole farm.
    Also, you can check the ULS logs to see if there is any unexpected error occurs when deploying this solution.
    About how to check the ULS logs:
    http://blogs.technet.com/b/fesiro/archive/2013/11/11/sharepoint-logging-and-troubleshooting-using-ulsviewer.aspx
    Thanks
    Patrick Liang
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Failed to install ms sql 2012, it shows 1406 Could not write value to key \SOFTWARE. Verify that you have sufficient access to that key, or contact your support personnel. error

    Hi friends,
    i have tried to install ms sql 2012 on windows 8.1 pro 64 bit  but it got failed due to the following error 1406 Could not write value  to key \SOFTWARE.   Verify that you have sufficient access to that key, or contact your support personnel.. 
     I had run the set up file as administrator. I have ony one user account on my laptop. I have seen in the regestry about permission of user. There is full control to the user. I have also tried the solution related to this issue that are available in
    this forum and other.
    I have also attache the detail.txt log file here
    So i am heartily requesting you guys if you have the solution then please post your solution as soon as possible. 
    Thanks in  advance!!!

    Looks like this is a permission issue with account you logged in in your operating system or account if any you chooses to run you SQL Server installation . Or for executing setup file try using run as administrator.
    http://www.sperrysoftware.com/kb/questions/7/How+to+Troubleshoot+a+%22Error+1406%3A+Could+not+write+value...%22+or+%22Error+1406%3A+Could+not+write+InstanceIndex+to+key...%22+error+message
    http://support.microsoft.com/kb/913559
    Raju Rasagounder Sr MSSQL DBA

  • SQL Command code for multiple value string parameter

    Hi,
    I'm using crystal 2008 and there is a check box for multiple value  SQL Command  I need some help in writing the SQL Command code  for oracle (or sql server) for a multiple value STRING  parameter.
    Thanks in advance,
    Marilyn

    I could be wrong here, but I do not believe you can pass a multiple valued parameter to an SQL Command data source.  How I have gotten around this in the past is to put the "real" report into a subreport.  In the main report, create a formula field (basic syntax):
    formula = join({?parameter}, "|")
    Then, use this to pass the selected values to the subreport's parameter (call it {?sr-parm}).  The SQL Command in the subreport can then use that (MS SQL):
    select *
    from table
    where charindex(table.field, '{?sr-parm}') > 0
    HTH,
    Carl

  • Retrieve Crystal SQL statements without first submitting parameter values?

    Hi,
    I am retrieving SQL statements for Crystal reports without issue, but a large number of our reports have parameters and for these the following error is thrown when I try to retrieve the SQL statement via RAS using getSQLStatement():
    com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException: Missing parameter values.---- Error code:-2147217394 Error code name:missingParameterValueError
    I have a large number of reports I'd like to pull SQL for, so it's not feasible to have my script push parameter values to each and every report.  Is there a way to retrieve SQL statements without first pushing parameter values?
    Thanks

    Hello Jeremy.
    I found a Knowledge Base article that deals with the "Error code:-2147217394 Error code name:missingParameterValueError" error that you mention.  Perhaps you could take a look at the following KBase Article in the Service MarketPlace and see if any of it applies to your situation:
    KBase number: 1420593
    I also found KBase number "1420501 - Report parameters ignored when set by Java post processing code" that seems to deal with the same problem.
    Regards.
    - Robert

  • SQL 2012 - SSIS Error -The step did not generate any output. The return value was unknown. The process exit code was -1073741819. The step failed.

    Hi guys 
     Trying to run this package on SQL 2012 agent  and getting below error . No more details I could find so far.
    The step did not generate any output.  The return value was unknown.  The process exit code was -1073741819.  The step failed.
    About Package - Its connecting to different version (2000,2005,2008,2008R2,2012) servers and putting Jobs information into one Database table.  
    Any workaround or fix ?
    Thanks
    Please Mark As Answer if it is helpful. \\Aim To Inspire Rather to Teach

    New package or one that used to work? Connecting how? How does it poll?
    On the surface it is an error from a memory space of the binary/non-managed code, so nothing can be really concluded based on what you decided to share with us.
    Arthur My Blog
    So Same package is working fine from my local machine which has SQL 2008 R2 and SQL 2012 installed. I am trying to push the package on server which has sql server 2012 Installed . 
    I don't see any error .
    I ran package manually from server using SQL Data tools and ran successfully...
    Please Mark As Answer if it is helpful. \\Aim To Inspire Rather to Teach

  • Parameter  value "Half year " is not accepting by while updating time dimen

    Hi,
    while i am updating "Time" dimention i am getting an error as parameter value "Halfyear" is not valid value. But system is  accepting Daily, Monthly, Quarterly and yearly under Level parameter.
    So please advise me how to proceed on this.
    Regards,
    M.Chandra Sekhar Chowdary

    Hi,
    This is definitely not the answer you might be expecting. We have it as 'DAY' for the level property values for H1 and H2(completely not reasonable). But you can process the TIME dimension with this 'value' for half year provided you dont have dates as your time members (which may be the case).
    Try using 'DAY' and process the dimension as a work around. We could wait if there is any other valid reason behind this (not taking 'halfyear').
    Thanks

  • Parameter Accepting Multiple Single Values Only

    I need to define a parameter that accepts multiple single values only but does not accept ranges or negations.  Basically I only want the first tab of the Select-Options screen.  Is this possible?

    Hello,
    Create a select-option as s_mara.
    At selection-screen output.
    loop at screen.
    if screen-fieldname = s_mara-high.
    screen-invisible = '1'.
    modify screen.
    endif.
    Try this. Hope this helps.
    Thanks & Regards,
    Anand Patil

  • Configuration Manager 2012: Report -software 06B-Parameter Value

    Customer is deploying IE 9 and would like to run the report to show the status.
    However, when they run the report-software 06B, the Parameter Value only list IE7,  no IE 8 and IE 9.
    Please help to solve this question, thanks.

    Yes I know this is an old post, I’m just trying to clean up old posts.
    That report is based on AI (ARP) data and therefore if you didn’t install IE 8 or 9 on a PC it will not be listed.
    http://www.enhansoft.com/

Maybe you are looking for