What incorrect syntax found in this query for dynamic search

I make this stored procedure for dynamic search by date from date to employee no employee name
but it give me error why
Create proc CollectsearchData15
@StartDate datetime,
@EndDate datetime,
@EmployeeID NVARCHAR(50),
@EmployeeName nvarchar(50)
as
Begin
DECLARE @SQLQuery as nvarchar(max)
SET @SQLQuery = N'SELECT * from ViewEmployeeTest Where (1=1)'
If @StartDate Is Not Null
SET @SQLQuery = @SQLQuery + N' And (joindate >= @StartDate)'
If @EndDate Is Not Null
SET @SQLQuery = @SQLQuery + N' And (joindate <= @EndDate)'
If @EmployeeID Is Not Null And @EmployeeID != ''
SET @SQLQuery = @SQLQuery + N' And (EmployeeID = @EmployeeID)'
If @EmployeeName Is Not Null And @EmployeeName != ''
SET @SQLQuery = @SQLQuery + N' And (DriverName Like ''%'' + @EmployeeName + ''%'')'
Print @SQLQuery;
Exec sp_executesql @SQLQuery,
N'@StartDate datetime, @EndDate datetime, @EmployeeID nvarchar(50), @EmployeeName nvarchar(50)',
@StartDate, @EndDate, @EmployeeID, @EmployeeName;
but it give me this error why
Msg 102, Level 15, State 1, Procedure CollectsearchData15, Line 28
Incorrect syntax near ';'.

I think you are missing an END. Perhaps with no dynamic sql :
SELECT * from ViewEmployeeTest
WHERE
(joindate >= @StartDate OR @StartDate IS NULL)
AND
(joindate <= @EndDate OR @EndDate IS NULL)
AND
(EmployeeID = @EmployeeID OR @EmployeeID IS NULL)
AND
(DriverName Like '%' + @EmployeeName + '%' OR @EmployeeName IS NULL)
Thanks and regards, Rishabh K
Please keep in mind that this might cause proc to generate bad plans
http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Similar Messages

  • How to tune this query for the improve performance ?

    Hi All,
    How to tune this query for the improve performance ?
    select a.claim_number,a.pay_cd,a.claim_occurrence_number,
    case
    when sum(case
    when a.payment_status_cd ='0'
    then a.payment_est_amt
    else 0
    end
    )=0
    then 0
    else (sum(case
    when a.payment_status_cd='0'and a.payment_est_amt > 0
    then a.payment_est_amt
    else 0
    end)
    - sum(case
    when a.payment_status_cd<>'0'
    then a.payment_amt
    else 0
    end))
    end as estimate
    from ins_claim_payment a
    where a.as_of_date between '31-jan-03' and '30-aug-06'
    and ( a.data_source = '25' or (a.data_source between '27' and '29'))
    and substr(a.pay_cd,1,1) IN ('2','3','4','8','9')
    group by a.claim_number, a.pay_cd, a.claim_occurrence_number
    Thank you,
    Mcka

    Mcka
    As well as EXPLAIN PLAN, let us know what proportion of rows are visited by this query. It may be that it is not using a full table scan when it should (or vice versa).
    And of course we'd need to know what indexes are available, and how selective they are for the predicated you have in this query ...
    Regards Nigel

  • Please help to modifiy this query for better performance

    Please help to rewrite this query for better performance. This is taking long time to execute.
    Table t_t_bil_bil_cycle_change contains 1200000 rows and table t_acctnumberTab countains  200000 rows.
    I have created index on ACCOUNT_ID
    Query is shown below
    update rbabu.t_t_bil_bil_cycle_change a
       set account_number =
           ( select distinct b.account_number
             from rbabu.t_acctnumberTab b
             where a.account_id = b.account_id
    Table structure  is shown below
    SQL> DESC t_acctnumberTab;
    Name           Type         Nullable Default Comments
    ACCOUNT_ID     NUMBER(10)                            
    ACCOUNT_NUMBER VARCHAR2(24)
    SQL> DESC t_t_bil_bil_cycle_change;
    Name                    Type         Nullable Default Comments
    ACCOUNT_ID              NUMBER(10)                            
    ACCOUNT_NUMBER          VARCHAR2(24) Y    

    Ishan's solution is good. I would avoid updating rows which already have the right value - it's a waste of time.
    You should have a UNIQUE or PRIMARY KEY constraint on t_acctnumberTab.account_id
    merge rbabu.t_t_bil_bil_cycle_change a
    using
          ( select distinct account_number, account_id
      from  rbabu.t_acctnumberTab
          ) t
    on    ( a.account_id = b.account_id
           and decode(a.account_number, b.account_number, 0, 1) = 1
    when matched then
      update set a.account_number = b.account_number

  • Can we write query for fomatted search without from clause

    can we write query for fomatted search without from clause as below.
    SELECT (($(u_amt)*14)/100)
    here U_amt is a UDF .I want to assign this to another field .
    Rgds,
    Rajeev

    Hi Rajeev,
    You can write query for FMS without from.  That is because you can omit it when you get value from active form by default.  The grammar of it is:
    Select $[$38.u_amt.0\] * 14/100 in your case if you have item type marketing document @line level.
    From View-System Information, you can get the info you need for your FMS query at the left bottom of your screen.
    Thanks,
    Gordon

  • What is the best way to query for the roles of a 2013 Lync server?

    I am new to Lync.
    I am not able to find, but if anyone already asked and got answers in this forum, or documentation I will be much appreciate. 
    I would like to programmatically ( powershell wmi most likely)
    Get-WmiObject –query ‘select * from win32_product’ | where {$_.name –ilike “*Lync*”}
    Typically returns a lot of installed components, is there a way to tell whether a lync ( 2013) installation and deployment is either a Front/Back, or Edge or Mediation?
    Thanks

    thanks. Although I was expecting  (hoping) to be able to query for roles like : Front/Back, Edge , Mediation, Director and etc.
    PS C:\Users\labuser> get-csservice | select PoolFqdn,Role,SiteId
    PoolFqdn                   Role                       SiteId
    lab-lync2013-01.lab.exc13  UserServer                 Site:lab-lync2013-01
    lab-lync2013-01.lab.exc13  Registrar                  Site:lab-lync2013-01
    lab-lync2013-01.lab.exc13  UserDatabase               Site:lab-lync2013-01
    lab-lync2013-01.lab.exc13  FileStore                  Site:lab-lync2013-01
    LAB-EXCH2013CAS            WacServer                  Site:lab-lync2013-01
    lab-lync2013-01.lab.exc13  WebServer                  Site:lab-lync2013-01
    lab-lync2013-01.lab.exc13  ConferencingServer         Site:lab-lync2013-01
    lab-lync2013-01.lab.exc13  MediationServer            Site:lab-lync2013-01
    lab-lync2013-01.lab.exc13  ApplicationServer          Site:lab-lync2013-01
    lab-lync2013-01.lab.exc13  ApplicationDatabase        Site:lab-lync2013-01
    lab-lync2013-01.lab.exc13  CentralManagement          Site:lab-lync2013-01
    lab-lync2013-01.lab.exc13  CentralManagementDatabase  Site:lab-lync2013-01
    lab-lync2013-01.lab.exc13  MonitoringDatabase         Site:lab-lync2013-01
    10.199.4.4                 PstnGateway                Site:lab-lync2013-01
    What if, I use get-counter instead?
    E.g. if I am able to get something returned for 
    \LS:A/V Edge - UDP Counters(_Total)\A/V Edge - Packets Dropped/sec  , then I know it has Edge role
    \LS:MediationServer then it has Mediation role
    But then I really cannot tell for sure for FF or just Standard Editor Server.
    It is the list of server roles described in here that I am interested in. I understand Lync is very flexible in terms of deployment roles.
    http://technet.microsoft.com/en-us/library/gg398536.aspx
    Thanks
    Ben

  • How can we rewrite this query for better performance

    Hi All,
    The below query is taking more time to run. Any ideas how to improve the performance by rewriting the query using NOT EXITS or any other way...
    Help Appreciated.
    /* Formatted on 2012/04/25 18:00 (Formatter Plus v4.8.8) */
    SELECT vendor_id
    FROM po_vendors
    WHERE end_date_active IS NULL
    AND enabled_flag = 'Y'
    and vendor_id NOT IN ( /* Formatted on 2012/04/25 18:25 (Formatter Plus v4.8.8) */
    SELECT vendor_id
    FROM po_headers_all
    WHERE TO_DATE (creation_date) BETWEEN TO_DATE (SYSDATE - 365)
    AND TO_DATE (SYSDATE))
    Thanks

    Try this one :
    This will help you for partial fetching of data
    SELECT /*+ first_rows(50) no_cpu_costing */
    vendor_id
    FROM po_vendors
    WHERE end_date_active IS NULL
    AND enabled_flag = 'Y'
    AND vendor_id NOT IN (
    SELECT vendor_id
    FROM po_headers_all
    WHERE TO_DATE (creation_date) BETWEEN TO_DATE (SYSDATE - 365)
    AND TO_DATE (SYSDATE))
    overall your query is also fine, because, the in this query the subquery always contain less data compare to main query.

  • Can u any imrove this query for maximum performance

    select g_com_bu_entity bunt_entity
         , g_com_rep_cd srep_cd
         , effdt from_dt
         , eff_status
         , g_com_role role
         , g_com_pgm prgm
         , g_com_district district
         , g_com_draw_status draw_status
         , decode(g_com_primary_pgm, 'Y',1, 0) pri_prgm_flag
    FROM ps_g_com_assign_vw@commissions c1
    WHERE effdt =
    (SELECT MAX (effdt)
    FROM ps_g_com_assign_vw@commissions c2
    WHERE c1.g_com_bu_entity = c2.g_com_bu_entity
    AND c1.g_com_rep_cd = c2.g_com_rep_cd);
    can anyone make it as regular query for maximum performance
    Thanks,
    Sreekanth

    Hi Sreekant,
    Try this: If it helps
    select g_com_bu_entity bunt_entity
    , g_com_rep_cd srep_cd
    , effdt from_dt
    , eff_status
    , g_com_role role
    , g_com_pgm prgm
    , g_com_district district
    , g_com_draw_status draw_status
    , decode(g_com_primary_pgm, 'Y',1, 0) pri_prgm_flag
    FROM ps_g_com_assign_vw@commissions c1,
    (SELECT MAX (effdt) effdt_max
    FROM ps_g_com_assign_vw@commissions c2
    WHERE c1.g_com_bu_entity = c2.g_com_bu_entity
    AND c1.g_com_rep_cd = c2.g_com_rep_cd) t2
    WHERE effdt = t2.effdt_max;

  • What do you think of this Design for Multiple Threads

    Hi Java Experts ;
    I'm curious to know what you think about this design for a multhreaded app i'm working on.
    I have a controller thread that (a.) creates threads and (b.) keeps a reference to threads that it creates (by sticking them in a hashtable along with the generated Id for that thread).
    When a created thread completes its job, it decrements the thread counter and removes its reference from the hashtable before it finishes its run method.
    Now here's the interesting part in my controller thread i'm creating new threads on the fly with this infinite loop
         public void run(){
              while(true){
                   try{
                        Thread.sleep(500);
                   }catch(InterruptedException e){
                   if(threadCounter<maxThreadCount && moreJobsToDo.size()>0){
                        createDomainThread();
              }//end while
    what do you think about this pattern ? My goal is to maintain about 200+ created threads running at all times with this pattern.

    jeff kesslerman's book says about threads
    "5.2.3 Threads
    The impact that threads have on RAM footprint isn't a problem for most programs, but running threads do need space to store their stack state, and the system- specific data structures do consume memory.
    Because runtime implementations vary widely in how threads are handled, you might encounter situations where the impact threads have on footprint is significant. For example, some ports of the JRE create a heavyweight OS process for each running thread. In an application that uses many threads, this means that thread costs, rather than class or object costs, can become the dominant factor in the program's memory consumption.
    You shouldn't avoid using threads-they're necessary in many cases, and generally don't have a large impact on footprint. However, you should be aware that the impact can be very different across runtimes. This is one of the reasons it's a good idea to measure performance characteristics under your program's different target environments. "
    Question #1: how does garbage collection go about clearing the stack state, and the system- specific data structures that consume memory.
    Question #2: in my situation, each worker thread's activity is not as brief as a simple server request. Each thread does a lot work and does a lot of network connections. on average I would say 100 http request - each of which can be easily blocked or delayed significantly. Therefore each worker thread may operate for between 2 - 10 minutes.
    Do you think thread pooling is useful in this situation ?
    stev

  • What is the best way to Query for a PXI Chassis in TestStand

    Hi All,
    I have some benches that have a PXI Chassis and others without. 
    I would like to Query for the Chassis and if it isn't there I will use another method of testing.
    Is there a way to query for the chassis and if there is how?
    Thanks
    Message Edited by glennjammin on 10-09-2009 09:23 AM
    Test Engineer
    L-3 Communications
    Solved!
    Go to Solution.

    Hi,
    You could use the VISA Find Resource function. If you get back PXI[bus]::device[::function][::INSTR] or PXI[interface]::[bus-]device[.function][::INSTR] then you have a PXI chassis
    regards
    Ray Farmer
    Regards
    Ray Farmer

  • How do I use "Search Query" for nontrivial searches?

    After a few years in the community, this is my _first_ question to the boards ;-)
    In speaking with a colleague today, I learned about an NI forum feature that would be useful for me. When I tried to configure it, I then learned that I didn't know how to use it. When I tried to learn how to use it, I further learned that it wasn't fully documented. So, I'd like some clarification :-)
    The feature in question is "Search Query" which will send you an email when a forum search matches your query. What I don't know is:
    What are the rules (syntax) for search queries? For example, I would like to search for single words, all the words that I specify, as well as exact phrases. How do I differentiate between multiword queries and exact phrase queries?
    Is it possible to have more than one Search Query?
    If so, how do you delineate them? Would I use commas, a new line, something else?
    I'm asking because the available (and discoverable) documentation doesn't mention what to do when you want more than one Search Query. The help text on the subscription page [1] makes me think that only one query is possible, and says a Search Query:
    Sends you mail every time a message matching your query is submitted. Search queries take up to 15 minutes to take effect. Saving a blank query will disable this feature and will stop any mail from being sent.
    The other place I tried was the NI Forum FAQ [2], which makes me think that more than one query is possible:
    If you add a board, thread, message, or search term to your subscriptions, the system will send you an e-mail every time someone posts to the board, or replies to the message or thread. If you prefer not to receive an e-mail for your subscriptions, you can subscribe to the RSS feed of a board, thread, user, or search term.
    The FAQ goes on about what to do with board, thread, and message subscriptions, but doesn't say anything more about search subscriptions.
    The last place I looked was on the search results page itself. In the blue header that precedes the results, there's a link on the far left that says "Search Options" with a single option that says "Subscribe to this search's RSS Feed". While I could subscribe and use an RSS reader, I really would prefer email. I suppose if only one Search Query is possible, then this will be my workaround.
    As a comment, why does the Search Options menu not also have a "Subscribe to this search" option, which would add another entry in the Search Query box? This is a noticeably different interface than the Thread Options menu.
    [1] Subscriptions & Bookmarks
    http://forums.ni.com/ni/user_subscriptions
    [2] Frequently Asked Questions
    http://forums.ni.com/ni/help_faq
    Joe Friedchicken
    NI VirtualBench Application Software
    Get with your fellow hardware users :: [ NI's VirtualBench User Group ]
    Get with your fellow OS users :: [ NI's Linux User Group ] [ NI's OS X User Group ]
    Get with your fellow developers :: [ NI's DAQmx Base User Group ] [ NI's DDK User Group ]
    Senior Software Engineer :: Multifunction Instruments Applications Group
    Software Engineer :: Measurements RLP Group (until Mar 2014)
    Applications Engineer :: High Speed Product Group (until Sep 2008)
    Solved!
    Go to Solution.

    Hi Joe,
    Thanks for all of the questions and congrats on posting your first question!
    Unfortunately I think all of your questions come from the valid assumption that the search query functionality is more robust than it actually is.  The search query functionality really only serves a single purpose and that is to email you when your phrase has been posted to the forums.  For me, I use it to email me when my name is mentioned in the forums.  It serves this purpose well since I have it set up to work off just a single search term.  However I find that multiple word phrases are combined with an OR which is not as useful.  The search query does not adhere to any common search syntax that you would expect (I believe we are the only community that uses this feature so it has not been improved upon).
    The best way to set up both multiple word queries and multiple different queries is to use the RSS feed as you mentioned.  This way you can tailor your search very specifically using different advanced search options and subscribe to them all in one feed reader without constantly getting emails.  The search query emails do not adhere to the digest subscription settings.  I find that the RSS feeds work very well for searches and I am fond of using them, but I do use an RSS Reader for many things so it is not out of my normal workflow.
    Thank you for reading the Forum FAQ.  I've done some work to improve it but I think it has a long way to go and it's good to know that people read it
    Regards,
    Laura
    Web Support & Operations
    National Instruments

  • Query for formatted search

    Hi All,
    I have a line UDF called U_PO in the sales order documents that denotes our purchase order number that particular item is ordered on.
    I have another line UDF called U_XMill which I want to populate with the corresponding PO document due date.
    What would be my query for that?
    Basically, it should be something like:
    SELECT T0.DocDueDate FROM OPOR T0 WHERE T0.DocNum=$[$38.44.0] FOR BROWSE
    However, I am sure that "38.44" is wrong.
    It should denote my current document's UDF *.U_PO.
    And I am not sure what would be the correct notation for it.
    I was wondering if there was a help document I could refer to to figure out the corresponding field numbers for the cases like this.
    Thank you for your help.

    Hello
    use FMS on matrix (tables) as
    [ItemUID.ColumnUID.Type] or [TableName.FieldName]
    where itemUID is 38
    ColumnUID is U_XMill
    Type is 0 (general).
    There is a now-to guide on service.sap.com/smb/sbo where you can find how to us FMS.
    Regards
    J

  • How to frame the select query for wildcard search.

    Hi Experts,
    I have an input field P_USERALIAS.This value could contain the actual value or the wildcard for example : user can enter P_USERALIAS as SAP123 or S or SAPABC123 . I need to generate a dynamic search on table USREFUS  depending on what has been entered.Please help.
    Useful answers will be rewarded.
    Regards,
    Shrita Sharma.

    THIS IS A TEST REPORT FOR WILDCARD SEARCH**
    TABLES: USREFUS.
    PARAMETERS: P_NAME1 TYPE string.
    RANGES: R_NAME1 FOR USREFUS-USERALIAS.
    DATA: T_usrefus LIKE usrefus OCCURS 0 WITH HEADER LINE.
    *replace
    if p_name1 cs '*'.
    replace all occurrences of '*' in p_name1 with '%'.
    SELECT * FROM usrefus
    INTO TABLE T_usrefus
    WHERE useralias like P_NAME1.
    else.
    SELECT * FROM usrefus
    INTO TABLE T_usrefus
    WHERE useralias = p_name1.
    endif.
    LOOP AT T_usrefus.
    WRITE: / T_usrefus-useralias.
    ENDLOOP.
    **THANKS & REGARDS
    SHRITA SHARMA.

  • What is the best method to query for older GPIB equipment with ID? and newer with *IDN?

    Good day,
    I am writing a test executive where it needs to scan the bus for support of older (HP/Agilent 856x series) and newer (Agilent 440x and 444x series) spectrum analyzers. *NOTE* I originally posted this question in my NI Community blog. I apologize for redundancy but someone recommended I re-post here.
    The first frame looks for the newer analyzers with *IDN? then if that fails sets the boolean in the error cluster to TRUE. The next frame then uses the error cluster's boolean to decide whether an older HP analzer is connected instead using ID? query. Disclaimer: the second frame is a clone of the ID query of the 856x Initialize VI. I just want to use what already worked - no reinventing the same wheel?
    But, lo and behold, it doesn't work as expected. If I have the frames in this order and connect a HP8563E the GPIB time's out error. This code works with the newer 4407 or 4440 since the *IDN? query passes and the second frame is not executed.
    Now, when I move the second frame to become the first frame and run it with HP8563E the query works but will have a GPIB timeout if I have the 4407 or 4440 connected.
    Long story short, how do I support both older GPIB ID? and newer IDN? in my code?
    I have attached the query VI created with LV 2012.
    Many thanks!
    Aldrin
    Attachments:
    Query ID and IDN.vi ‏11 KB

    I think Michael Aivaliotis of JKI and NI have an elegant solution:
    https://decibel.ni.com/content/groups/large-labview-application-development/blog/2015/05/14/what-is-...
    Cheers!
    Aldrin

  • Why Syntax error in this query?

    Hi
    I have this simple query, but in run time I have a "sytax error in INSERT INTO". Why?
    Statement st = con.createStatement();
    st.executeUpdate("INSERT INTO TMail (From, Oggetto) VALUES ('" +
    from + "', '" + mex.getSubject() +
    "')");

    If it's not a problem with a reserved word, then you're probably generating an invalid query. You need to print your query out and see what the query is.
    Also, many many many SQL problems can be avoided (nad you'll have cleaner, faster code), if you use PreparedStatement instead of Statement. Statement is for amateurs...
    static final String SQL = "INSERT INTO TMail (From, Oggetto) VALUES (?, ?)";
    PreparedStatement ps = con.prepareStatement(SQL);
    ps.setString(1, from);
    ps.setString(2, mex.getSubject() );
    ps.executeUpdate();

  • What are the concurrent programs or query for safe purge to claim  space

    I am using Apps R12.1.3 and database 11g Enterprise Edition(11.1.0.7.0) .Due to excess increase in the tablespace sizes,i want to know
    What are the application tables which contains logs and unwanted information which we can purge safely without affecting user data.
    And how to purge them (any query or concurrent program)?

    Hi,
    We discussed this many times before.
    Please use the following link where you will get many (all) refereces
    https://forums.oracle.com/forums/search.jspa?threadID=&q=Purge&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks

Maybe you are looking for

  • How can I set a music from my music library as a Ringtone on my Iphone?

    How can I set a music from my music library as a Ringtone on my Iphone?

  • 'Some images are missing because they were deleted from the document'

    Hi, I created a document in Pages v5.2 last week and have just opened it and received the following message: 'Some images are missing because they were deleted from the document' When I try and replace the missing images I get the following message:

  • OMWB 1.3 hangs while mapping tables from SQLServer 7

    I am converting a SQLServer 7 database to Oracle 8.1.7. As soon as the Oracle model creation process gets to Mapping tables, the OMWB hangs and has to be killed off. Any help would be appreciated. Here is the error log. ** Oracle Migration Workbench

  • Search Never Finishes in IE

    Hello everyone, I have a set of files given to me by one of our Engineers. I understand they built these help files from our regular .hlp files. It appears they were built using DHTML. opening a local copy of the html pages the search tab seems to wo

  • Af:tree group by one or more view attribute(s)

    Hi. How to create af:tree with one or more levels based on one or more attribute's group by? I have a view with two attributes (Attr1 (possible values are 1 or 2) and Attr2 (value is string like name)). I want to create tree with root level of Attr1