Checking multiple IF conditions

I'm working on a stored procedure and having issues.  I want to check two conditions and is none of them are met, Insert a new record. In the first 2 checks, If I find a match I will hold that value and update later in the script.  If I can't
find a match, the 3rd step will add a new record to the location table and I will hold that value and use it to update later in the script.  Any help would be appreciated.
IF @Is_Flag = 'N'
BEGIN
IF EXISTS (select * from Location where Institution_Nm = @Institution_Nm )
BEGIN
Set @Location_Id = (Select Location_id from Location where Institution_Nm = @Institution_Nm)
END
ELSE
BEGIN
set @Location_Id = (Select Location_Id from Research_Project_Detail Where Research_Project_Id=@Research_Project_Id and Term_Id=@Term_Id and Is_flag = 'N')
END;
Update Location Set State_Id=@State_Id, Country_Id=@Country_Id, Institution_Nm=@Institution_Nm,ModifiedBy=@ModifiedBy,Modified_Dt=GETDATE() Where Location_Id=@Location_Id
END
ELSE --CAN'T FIND ONE...INSERT NEW ONE and hold the ID
BEGIN
Insert into Location ( State_Id, Country_Id, Institution_Nm,CreatedBy,Created_Dt) Values (@State_Id, @Country_Id, @Institution_Nm,@ModifiedBy,GETDATE())
set @Location_Id = Scope_Identity( )
select Scope_Identity( ) Location_Id
END

>> I'm working on a stored procedure and having issues. <<
Yes; you have no idea how to write SQL, so you write COBOL or BASIC in SQL. Your code is not declarative, but classic procedural programming. 
You do not even know that rows are not records! This is fundamental. You are using IDENTITY because it looks like a record number on a 1950's magnetic tape. Your files had singular names because the unit of work in files is a record; in RDBMS, we use plural
names to show that tables are sets. 
You use flags because that is how you wrote in assembly language or COBOL. 
But worse, you keep audit information in the same table! This is illegal. 
>> I want to check two conditions and is none of them are met, Insert a new record [sic]. In the first 2 checks, If I find a match I will hold that value and update later in the script. <<
No, in a declarative language; we have no local variables and no concept of later sequential execution. 
>> If I can't find a match, the 3rd step [sic] will add a new record [sic] to the Locations table and I will hold that value and use it to update later in the script. <<
Do you know about the SAN (Standard Address Number) used in several industries? ISO country codes, state codes are NOT ids. The old Sybase GETDATE() is now the ANSI/ISO Standard CURRENT_TIMESTAMP in T-SQL; you did an illegal act with bad code. 
>> Any help would be appreciated. <<
You need a major education, not just a kludge. The schema needs to be thrown out and done correctly. Without DDL, we can only guess, but I think that once you fixed the schema, the statement would be something like this skeleton: 
MERGE INTO Locations AS L
USING 
   (SELECT X.* 
      FROM (VALUES (@in_state_code, @in_country_code, @in_institution_name))
AS X (state_code, country_code, institution_name)) AS N 
ON @in_research_project_id = L.research_project_id
   AND @in_term_id = L.term_id  
WHEN MATCHED
THEN UPDATE
  SET state_code = N.state_code, 
      country_code = N.country_code,
      institution_name = N.institution_name
WHEN NOT MATCHED
THEN INSERT  state_code, country_code, institution_name
     VALUES (@in_state_code, @in_country_code, @in_institution_name);
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • Check Multiple Value Condition

    Hi,
    I am preparing a query to show the data which are not in table TECH_SOURCING_EMP_ACTUAL_HOURS, In this table there are unique combination ID'S
    EMPLOYEE_ID AND PROJECT_ID
    /* I need to check from the below query to see which are records which are in table TECH_SOURCING_EMP_ACTUAL_HOURS */
    SELECT
    TD.EMPLOYEE_ID,
    PRJ.PROJECT_ID
    FROM TECH_SOURCING_EMPLOYEE_DETAILS TD,
    TECH_SOURCING_EMP_PROJECT PRJ AND
    /* TD.EMPLOYEE_ID, PRJ.PROJECT_ID
    NOT IN ( SELECT EMPLOYEE_ID,PROJECT_ID FROM TECH_SOURCING_EMP_ACTUAL_HOURS ) */
    Is there any method to check two unique combinations. Please suggest
    Thanks
    Sudhir

    Sudhir_Meru wrote:
    Yes exactly the same way i want to achiveDoes the clause I posted not work? If not, please see the thread I linked to and post a concise example of what you need, including output, CREATE TABLE, and INSERT statements.

  • Checking Multiple condition in Mapping

    Hi ,
    I need to check multiple OR condition in Message mapping should i need to write an U.D.F.
    For example:I has a field
    MATNR where the possible values are WE,WB,AR
    I need to check the condition Using OR condition
    MATNR  
                         EQUALS   
    WE
    MATNR              EQUALS
    WB
    MATNR             EQUALS
    BB

    use boolean function OR  & equal...
    MATNR     
                      ------- equals -------
    CONST(WE)                         |
                                                OR-----------------------
    MATNR                                  |                         |
                     ------- equals ----------                          OR -----------Output?
    CONST(WB)                       MATNR                   |
                                                       ----- equals -----------
                                            CONST(BB)
    Edited by: Anand on Nov 29, 2008 3:04 PM
    Edited by: Anand on Nov 29, 2008 3:06 PM

  • Adhoc Query : Error during selection; check the selection conditions

    Hi
    We have a report set-up and which we want to run using our adhoc query report tcode S_PH0_48000513
    The report, has a few different selection criteria in it to look at all action IT screen data in the system for ee's in specific personnel areas. There is also a criteria to allow us to paste in specific employee numbers we are interested in. The issue I am facing is that over about 3000 ids, the system automatically returns me a message when I click on the Output button to run the report which states:
    Error during selection; check the selection conditions
    Message no. PAIS206
    I am not sure why this is happening. The selection criteria are fine and the other day I ran the report and I experienced no issues. The report ran successfully. Now though, if I try and paste in all the ids I am interested in (about 8000) I get this message straightaway.
    Can anything be done to overcome this issue?
    Any advice would be much appreciated.
    Nicola

    Hi
    The message in full is:
    Error during selection; check the selection conditions
    Message no. PAIS206
    Diagnosis
    A runtime error occurred during dynamic selection.
    System response
    The runtime error will be caught; no short dump will be created. This error should not occur as a rule. However, very large select statements may trigger the runtime error SAPSQL_STMNT_TOO_LARGE or DBIF_RSQL_INVALID_RSQL. There is no way to prevent this happening. In this case, the error can only be caught.
    Procedure
    Check the selection conditions to see whether the error was caused because the option "Import from text file" included too many objects in the "Multiple selection" dialog. If this is so, you must limit the number of individual values.

  • How to add multiple test conditions in 'test' attribute expression of xsl:if tag

    Hi all,
    How to add multiple test conditions in 'test' attribute expression of <xsl:if> tag ?
    I have 2 parameters and I want To skip the massage if this 2 conditions happened I tried to write it :
            <xsl:when test="($TransferToCompany = 0 and $ObjectInclide=1 )">
            <b1im_skip xmlns="" info=" Obect Will Not Transfer To company">
            </b1im_skip>
          </xsl:when>
    But I get an error while I am trying to transfer The object (Account) true B1if
    I am working with SBO 9 PL 13
    thank you
    shachar

    Hi saado
    Check this link:
    http://stackoverflow.com/questions/318875/can-you-put-two-conditions-in-an-xslt-test-attribute
    Kind regards,
    Radek

  • Multiple "FromAddressContainsWords" Conditions in One Rule via PowerShell?

    My organization recently moved to Exchange Online and I am looking at trying to convert the old mail rules from our old system (Sieve rules from Zimbra) to something that will work in Exchange Online.  My plan is to massage the Sieve output into New-InboxRule
    statements.  The massaging part is the easy part.  What I'm having difficult with is using PowerShell to recreate a rule that should have multiple -FromAddressContainsWords parameters.  Here's what I started off with:
    New-InboxRule -Name "Annoyances" -FromAddressContainsWords roxioemail.com -FromAddressContainsWords "Covalent Technologies" -FromAddressContainsWords process.con -FromAddressContainsWords [email protected] -DeleteMessage $true -StopProcessingRules -Mailbox George.Lenzer
    This didn't work as the -FromAddressContainsWords option can only be used once.  The error also suggested trying to do an array if the parameter would accept one.  I don't know, because that isn't documented anywhere.  The only thing mentioned
    in the help is that it will take a "MultivaluedProperty" which I assume means some sort of string or array that has multiple values in it.
    I then tried this:
    New-InboxRule -Name "Junk Mail" -FromAddressContainsWords {roxioemail.com; Covalent Technologies; process.com; [email protected]} -DeleteMessage $true -StopProcessingRules $true -Mailbox George.Lenzer
    While this worked, when I went into OWA to look at the rule and check the list of words, instead of each word on it's own line, had a single entry containing everything between { and }.  This doesn't look right, and I don't expect it would do what I
    want.  So how does one go about creating an Inbox rule from PowerShell that needs to check multiple conditions, some of the identical type?  It can be done from the GUI, so there must be a way to do it from PowerShell.  Any suggestions?

    Hi George.  Thanks for posting in the forums.  Looking at both of your code snippets, I can see where the problem is.  MultivaluedProperties in PowerShell are exactly as you describe: a set of properties presented as a single argument to a
    parameter.  The mistake you made was attempting to use the semicolon to separate the items in your multivalued property and then trying to present them as a single string.  This is why you get the whole blob of text between the squiggly braces.
    Before I give you the solution, let me say that what you want is to pass an array to -FromAddressContainsWords.  In PowerShell. the comma along with multiple quoted strings is what defines an array.  See here for a better explanation than I can
    give:
     http://theessentialexchange.com/blogs/michael/archive/2008/02/08/Multivalued-Parameters-.aspx
    With that said, here's the solution to your issue:
    New-InboxRule -Name "Junk Mail" -FromAddressContainsWords ("roxioemail.com", "Covalent Technologies", "process.com", "[email protected]") -DeleteMessage $true -StopProcessingRules
    $true -Mailbox George.Lenzer
    Hope this helps!

  • Multiple pricing condition

    Hello experts,
    We have created a manual item condition for pricing but we have a problem when we enter the rate for that in the pricing screen.
    For example,
    "ZA01" is the one we created. Whenever we enter the value for that it automatically adds another line again and again after going to main order screen and back into Pricing screen again.
    ZA01 Discount for Rb              <- new line added
    ZA01 Discount for Rb    10.000 %  <- again
    ZA01 Discount for Rb    10.000 %
    It looks like this condition has multiple entry capability. I'm not familiar with item condition configuration but is there any way to prevent redundant multiple item condition entries?
    And also, from programming point of view, is it possible to delete manual item condition or combine it togther (10+10=20%)in XKOMV in one of the USEREXIT_XKOMV_... ?
    Regards,

    Hi,
    I think this condition type has been activated  as header condition as well as item condition, check in configurations...
    Its not a better way to delete/combine the condition values technically. Check out the configurations.
    Message was edited by: JITHENDRA CHADICHAL

  • Using multiple 'and' conditions in a SQL query

    Is it possible to reduce the SQL required to query using multiple 'and' conditions, e.g. I have a query like the following:
    select stat.personal_id, appt.username, appt.password, apps.rgn_apt_id, apps.apy_apn_id
    from apy_ast_application_status stat, rgn_usr_user appt, rgn_aps_applications apps
    where stat.apy_apn_id = apps.rgn_apt_id
    and apps.rgn_apt_id = appt.rgn_apt_id
    and stat.application_completed is null
    and stat.application_started_date > '01-MAY-11'
    and stat.amount_paid is null
    and stat.personal_details = 'C'
    and stat.further_details = 'C'
    and stat.education = 'C'
    and stat.employment = 'C'
    and stat.personal_statement = 'C'
    and stat.choices = 'C'
    and stat.reference = 'C'
    and stat.student_finance = 'C'
    Is there a way, to reduce all the multiple 'and' queries, to be read from say one line? If you know what I mean.......

    Ah, Ok this looks nice, thanks very much. It doesn't quite run as is because the stat.amount_paid query value is 'is null', while the others are 'C'. I tried amending the relevant line to various versions of the following:-
    in (select 'is null' 'C','C','C','C','C','C','C','C' from dual)
    which doesn't work.
    I can get the following to work so I am assuming that the it is not possible to use different query values within the brackets of the 'in (select....' statement?
    select stat.personal_id, appt.username, appt.password, apps.rgn_apt_id, apps.apy_apn_id
    from apy_ast_application_status stat, rgn_usr_user appt, rgn_aps_applications apps
    where stat.apy_apn_id = apps.rgn_apt_id
    and apps.rgn_apt_id = appt.rgn_apt_id
    and stat.application_completed is null
    and stat.application_started_date > '01-MAY-11'
    and stat.amount_paid is null
    and (stat.personal_details, stat.further_details, stat.education,
    stat.employment, stat.personal_statement, stat.choices, stat.reference, stat.student_finance)
    in (select 'C','C','C','C','C','C','C','C' from dual)
    Thanks for everybodys help - the suggested alternatives seem so much more elegant

  • How to update multiple Price conditions in FM CRM_ORDER_MAINTAIN

    Hi All,
          need to update multiple price conditions in a contract Thru FM CRM_ORDER_MAINTAIN.
    please see the piece of code that am using...
      am able to update single price condition...but not able to populate 2 or more .......i,e..ADD A Condition
    i,e...DATA : ls_cond TYPE prct_cond_external_input,
           lt_cond TYPE prct_cond_external_input_t.
    DATA : ls_con TYPE PRCT_COND_DU,
           lt_con TYPE PRCT_COND_DU_TAB.
    Create Condition Type
    *ls_con-KNUMV = lv_header_guid.
    *ls_con-KPOSN = lv_item_guid.
    ls_con-stunr  = '134'.
    IF Y EQ 1.
      ls_con-ZAEHK = '001'.
    ELSE.
       ls_con-ZAEHK = '002'.
    *ENDIF.
    *ls_con-kschl = 'ZFP1'.
    **ls_cond-waers = 'CNY'.
    *ls_con-kbetr = '0.00'.
    *ls_con-kpein = '1'.
    ls_cond-kschl = 'ZFP1'.
    ls_cond-waers = 'CNY'.
    ls_cond-kbetr = '0'.
    ls_cond-kpein = '1'.
    ls_cond-knumh = lv_item_guid .
    CLEAR ls_Price_doc.
    ls_Price_doc-ref_guid = lv_item_guid.
    ls_Price_doc-ref_kind = 'A'.
    IF Y EQ 1.
    ls_Price_doc-ref_handle = '000000001'.
    ELSE.
      ls_Price_doc-ref_handle = '000000002'.
    ENDIF.
    *ls_price_doc-PRIC_COND[] = lt_cond[].
    *INSERT ls_con into table ls_price_doc-PRIC_COND.
    INSERT ls_cond into table ls_price_doc-COND_ADD.
    INSERT ls_price_doc INTO TABLE lt_price_doc.
    ls_input_fields-ref_guid    = lv_item_guid.
    ls_input_field_names-fieldname = 'KNUMH'.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    ls_input_field_names-fieldname = 'KPOSN'.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    ls_input_field_names-fieldname = 'KSCHL'.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    ls_input_field_names-fieldname = 'KPEIN'.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    ls_input_field_names-fieldname = 'STUNR'.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    ls_input_field_names-fieldname = 'ZAEHK'.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    ls_input_field_names-fieldname = 'WAERS'.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    ls_input_field_names-fieldname = 'KBETR'.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    CLEAR ls_input_fields.
    Ls_input_fields-ref_guid    = lv_item_guid.
    ls_input_fields-ref_kind    = 'B'.
    ls_input_fields-objectname  = 'PRIDOC'.
    *ls_input_fields-logical_key = '0001'.
    ls_input_fields-field_names = lt_input_field_names.
    INSERT ls_input_fields INTO TABLE lt_input_fields.
    CLEAR ls_input_fields.
    CLEAR ls_Price_agreement.
    Clear ls_cond.
    I kept this under code. loop, for item records.....
    Though the internal table lt_price_doc. is holding all the records, it is updating only one record. can you any one pls guide me ,

    This example works fine for me. Modify it according to your needs...
    Price
                  IF it_item-value IS NOT INITIAL.
                    ls_cond-kschl = 'PR00'. " add price
                    ls_cond-kbetr = it_item-value.
                    ls_cond-waers = st_head-currency.
                    INSERT ls_cond INTO TABLE ls_pridoc_com-cond_add.   
                    index_2 = 1.
                    CLEAR: ls_cond.
                  ENDIF.
    Discount
                  IF it_item-discount IS NOT INITIAL.
                    ls_cond-kschl = 'ZPPP'. " add discount
                    wa_procent_calc = it_item-discount * 10.
                    ls_cond-kbetr = wa_procent_calc."it_item-discount.
                    ls_cond-waers = '%'."st_head-currency.
                    INSERT ls_cond INTO TABLE ls_pridoc_com-cond_add.   
                    index_2 = 1.
                    CLEAR: ls_cond, wa_procent_calc.
                  ENDIF.
                  IF index_2 = 1.
                    ls_pridoc_com-ref_handle = counter.
                    ls_pridoc_com-ref_kind = 'B'.
                    INSERT ls_pridoc_com INTO TABLE gt_pridoc_com.
                    CLEAR: index_2,ls_pridoc_com.
                  ENDIF.

  • How do I "check" multiple songs at same time?

    I'm trying to backup my itunes library to DVD, but itunes will only burn songs from a playlist if the box is checked. I have 900+ songs that are unchecked that I need to backup. I realize I can just re-import them from the original CD, but then I will also have to rate the songs all over again.
    A. How do I check multiple songs, or...
    B. Is there another way to backup the ratings data for each song?

    Highlight all the songs that you want, you could hit command+A to select them all.
    Then right click, or control+click and choose "Check Selections"
    "D"

  • How to check multiple special characters in instr function sql query.

    Hi,
    The following special characters are comma(,), slash(/), colan(:)
    these special characters i need to be check in instr function.
    select SUBSTR(master_title,1,INSTR(master_title,',',1,1)-1) from dual;
    Can you please write the query with right answer.
    Thanks in advance,
    Lakshman.

    Why multiple post?
    How to check multiple special characters in this query.

  • Multiple VAT condition on traderpass excise amount

    I would like to post MIRO where traderpass excise is included.I have done all the process of genrating GRN till posting excise duty. My tax code contains two VAT conditions i.e. 4% & 1% it is calulating VAT 1% on excise amount but 4% VAT is calculating only on basic value
    Kindly suggest
    Sanjay

    Hi,
    This seems to be 4% VAT & 1% additional tax rate & base for these two is same.
    Whether you have created new condition for this 1% rate other than JVRD,JVRN,JVCD,JVCN?
    If yes, then check in Classify Conditions types, which description you have assigned.
    If you have created new condition,then probably you have to check the routine for the same.
    Regards,
    Piyush

  • I made a card using the iPhoto and when I click to buy it, it says that I did not fill all the frames with pictures, even though I did and have checked multiple times. Please help, it's for Mother's Day.

    I made a card using the iPhoto and when I click to buy it, it says that I did not fill all the frames with pictures and that I need to in order to purchase it, even though I did and have checked multiple times. Please help, it's for Mother's Day.

    Before ordering your book preview it using this method - http://support.apple.com/kb/HT1040 - and save the resulting PDF for reference - the delivered book will match it.
    LN

  • Check one box to check multiple boxes

    I have created a javascript so that one checkbox will check multiple boxes.
    if 
    (this.rawValue==1){button1.rawValue
    =1};
    if  (this.rawValue==0){button1.rawValue
    =0};
    The problem is that I have about 15 of these "Check all" checkboxes to create and around 24 buttons underneath each one.
    Is there a better way to script the check all button, maybe something that will check all the boxes in a subform?

    Ok, in the test I ran, this worked. But there is a catch.
    My checkboxes are named things like AEMN, AEMP, CALF, CILCO and the such. What i would do is rename these in the Hierarchy to CB_AEMN, CB_CALF.  is there a wildcard that can be put on the cb to pick up the changes?
    xfa.resolveNode("page1.subform1.cb["
    + i + "]").rawValue =1;

  • Acrobat DC can no longer check multiple comments

    You guys, I am feeling kind of sad because I can no longer check multiple comments at once.
    In the last version of Acrobat Pro I could select more than one comment and then check one of the selected check boxes and all selected comments would be marked checked.  This saved me time when I was working through a couple of hundred corrections in a PDF and wanted to keep track of the ones I'd done.
    I'm not sure why this feature would now be disabled in Acrobat DC but I hope Adobe bring it back soon.
    Then again maybe there is a way to do it - anybody else worked this one out?

    actually there is a way to do it. You have to select the last comment on the list and then press the shift key and check the comment. This will mark off all the comments. This works okay with a document with say 100 comments, but if your document has over 1,000 comments then this is very much hit and miss. In that case you are better off opening the same file in Adobe Reader XI providing you didn't update that.
    Abother more irritating bug is the fact that if a word is highlighted then the words are hidden until you actually select the wordAAl
    All in all, Acrobat DC isn't ready for production purposes. I wasted many hours trying to use it until I realised that I could still use Adobe Reader XI.

Maybe you are looking for

  • OB52 and MMPV

    Hi, I am having a query on the posting periodsin OB52. I am aware that ob52 is a screen where we can open and close the posting periods. If I have a posting peroiod variant Z and I have assigned +(account type) then am not in need of metioning the fr

  • After cancelling the  billing document accounting document not generated

    hi, we released the billing and accounting document generated but customer needed changes in the billing values so we cancel the billing document but accounting document not generated(reversal accounting not happen)....in document flow it shows in ca

  • Group and group counter in sap

    Hi all, when i am creating rate routing while how can i change group number, external entry is not possible for group.,

  • Dropdown List in report program

    Hi Anybody send me the Dropdown list coding for a parameter in s selection-screen of a normal report program without using a module-program regards paul

  • All I get is a gray screen

    I just registered. I tried accessing Buzzword and Connect Now... All I got after the page is loaded is a dark gray screen... I waited, but nothing happened. Anyone?