Query WHERE statement to compare db record date pt 2

I'm sorry, I hit the answered button on my last post. I didn't mean to. I have been working on this code and have gotten closer to the solution. I just need to tweek out the WHERE statement to get rid of the time from the output, and I believe my cfif needs a little work to allow it to be taken into the actually dates. I cfdumped my variables from my query and finally got an output and not an [empty string]. This is my code now, and I will leave in the cfdump and abort tags so you can see where I put them:
<cfquery name="CaleventRec" datasource="#APPLICATION.dataSource#">
SELECT events.eventDate, events.ID AS ID
FROM events
WHERE eventDate Between #NextMonthYear# and #NextMonth# AND eventDate >= #dateFormat(Days, 'dd')#
</cfquery>
this is my cfif stement
<cfoutput query="CaleventRec">
<cfdump var="#eventDate#">
<cfabort>
<cfif Days EQ '#eventDate#'>
<a href = "detail.cfm?id=#ID#">#Days#</a>
</cfif>
</cfoutput>
this is the whole code:
<cfquery name="CaleventRec" datasource="#APPLICATION.dataSource#">
SELECT events.eventDate, events.ID AS ID
FROM events
WHERE eventDate Between #NextMonthYear# and #NextMonth# AND eventDate >= #dateFormat(Days, 'dd')#
</cfquery>
                        <!--- Set the ThisDay variable to 0. This value will remain 0 until the day of the week on which the first day of the month falls on is reached. --->
                        <cfset ThisDay = 0>
                        <!--- Loop through until the number of days in the month is reached. --->
                        <cfloop condition = "ThisDay LTE Days">
                            <tr>
                            <!--- Loop though each day of the week. --->
                            <cfloop from = "1" to = "7" index = "LoopDay">
                            <!--- This turns each day into a hyperlink if it is a current or future date --->
                              <cfoutput query="CaleventRec">
          <cfdump var="#eventDate#">
                               <cfabort>
          <cfif Days EQ '#eventDate#'>
                               <a href = "detail.cfm?id=#ID#">#Days#</a>
                               </cfif>
          </cfoutput>
                            <!---
                                If ThisDay is still 0, check to see if the current day of the week in the loop matches the day of the week for the first day of the month.
                                If the values match, set ThisDay to 1.
                                Otherwise, the value will remain 0 until the correct day of the week is found.
                            --->
                                <cfif ThisDay IS 0>
                                    <cfif DayOfWeek(ThisMonthYear) IS LoopDay>
                                        <cfset ThisDay = 1>
                                    </cfif>
                                </cfif>
                            <!---
                                If the ThisDay value is still 0, or is greater than the number of days in the month, display nothing in the column. Otherwise, dispplay
                                the day of the mnth and increment the value.
                            --->
                                    <cfif (ThisDay IS NOT 0) AND (ThisDay LTE Days)>
                                    <cfoutput>
                                    <!--- I choose to highlight the current day of the year using an IF-ELSE. --->
                                        <cfif (#ThisDay# EQ #currentday#) AND (#month# EQ #startmonth#) AND (#year# EQ #startyear#)>
                                            <td align = "center" bgcolor="##FFFF99">
                                                <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
            <font class = "calendartoday">#ThisDay#</font>
                                            </td>
                                        <cfelse>
                                            <td align = "center">
                                                <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
            <font class = "calendar">#ThisDay#</font>
                                            </td>
                                        </cfif>
                                    </cfoutput>
                                    <cfset ThisDay = ThisDay + 1>
                                    <cfelse>
                                        <td></td>
                                </cfif>
                            </cfloop>
                            </tr>
                    </cfloop>
the output from the cfdump is this: the first event date in the month of june.
I need this to match the thisday part of the code in the cfloop function through the days of the week.
Can anyone help me figure this part out?
thank you, and really sorry about the 2nd post. I just woke up and hit the wrong button. again, really sorry all.
CFmonger

This is a small calendar. it will move to the next month at the end of this one, it can also go to the next month with a next / prev button that will let you go as far as you want. It is like all we have seen before. What I need to do it get the eventDate in my DB, that is set as date and put in as mm/dd/yyyy now, basically what I believe the query needs to do it to not only tell what month the calendar is on, but it needs to match any db records with any of the days in that month. Say we are in June: I have 3 records in June, on the 5th, 20th, and 26th. In all the 31 days in the month of June, just those 3 will show a link with an ID to the record that matches in the DB.
I had it narrowed down with that query, but lose the variable once I try and cfif it. So I knew either my query is wrong, or my cfif is, probably both.
does that help? can I make this work? am I even close?
thank you.
CFmonger
By the way, here is the entire code with the next / prev nav for cycling through the months.
<!--- Declaration of the variables --->
       <cfparam name = "month" default = "#DatePart('m', Now())#">
<cfparam name = "year" default = "#DatePart('yyyy', Now())#">
<cfparam name = "currentday" default = "#DatePart('d', Now())#">
<cfparam name = "startmonth" default = "#DatePart('m', Now())#">
<cfparam name = "startyear" default = "#DatePart('yyyy', Now())#">
<!--- Set a requested (or current) month/year date and determine the number of days in the month. --->
<cfset ThisMonthYear = CreateDate(year, month, '1')>
<cfset Days = DaysInMonth(ThisMonthYear)>
<!--- Set the values for the previous and next months for the back/next links.--->
<cfset LastMonthYear = DateAdd('m', -1, ThisMonthYear)>
<cfset LastMonth = DatePart('m', LastMonthYear)>
<cfset LastYear = DatePart('yyyy', LastMonthYear)>
<cfset NextMonthYear = DateAdd('m', 1, ThisMonthYear)>
<cfset NextMonth = DatePart('m', NextMonthYear)>
<cfset NextYear = DatePart('yyyy', NextMonthYear)>
<cfset PreviousDay = DateAdd('d', -1, ThisMonthYear)>
<cfset CurrentYear = DatePart('yyyy', Now())>
<table border="0" width="100%" bgcolor ="#ffffff">
            <tr>
                <td align = "center" valign="top">
                    <table border="0" width="100%" height="100%">
   <tr>
      <th align="center" colspan="7" bgcolor="#2b4e6e">
   <cfoutput>
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15%" align="left" valign="middle">
  <cfif (LastYear lt CurrentYear) OR (LastYear lte CurrentYear AND LastMonth lt startmonth)>
<cfelse>
  <a href ="index.cfm?month=#LastMonth#&year=#LastYear#" class="calNav">Prev</a></cfif></td>
        <td width="72%" align="center" valign="middle"><FONT SIZE="3" face="Arial, Helvetica, sans-serif" color="##ffffff">#MonthAsString(month)# #year#</FONT></td>
        <td width="13%" align="right" valign="middle">
  <cfif (NextYear lt CurrentYear) OR (NextYear lte CurrentYear AND NextMonth lt startmonth)>
<cfelse>
<a href = "index.cfm?month=#NextMonth#&year=#NextYear#" class="calNav">Next</a>  </cfif></td>
      </tr>
    </table></cfoutput></th>
   </tr>
   <tr>
    <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Sun</FONT></td>
    <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Mon</FONT></td>
    <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Tue</FONT></td>
    <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Wed</FONT></td>
    <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Thu</FONT></td>
    <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Fri</FONT></td>
    <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Sat</FONT></td>
   </tr>
<cfquery name="CaleventRec" datasource="#APPLICATION.dataSource#">
SELECT events.eventDate, events.ID AS ID
FROM events
WHERE eventDate Between #NextMonthYear# and #NextMonth# AND eventDate >= #dateFormat(Days, 'dd')#
</cfquery>
                        <!--- Set the ThisDay variable to 0. This value will remain 0 until the day of the week on which the first day of the month falls on is reached. --->
                        <cfset ThisDay = 0>
                        <!--- Loop through until the number of days in the month is reached. --->
                        <cfloop condition = "ThisDay LTE Days">
                            <tr>
                            <!--- Loop though each day of the week. --->
                            <cfloop from = "1" to = "7" index = "LoopDay">
                            <!--- This turns each day into a hyperlink if it is a current or future date --->
         <cfoutput query="CaleventRec">
          <!---  <cfdump var="#eventDate#">
                               <cfabort>--->
          <cfif #dateFormat(eventDate, 'dd')# IS ('Days, LoopDay')>
          <cfdump var="#eventDate#">
                               <cfabort>
                               <a href = "detail.cfm?id=#ID#">#Days#</a>
                               </cfif>
          </cfoutput>
                            <!---
                                If ThisDay is still 0, check to see if the current day of the week in the loop matches the day of the week for the first day of the month.
                                If the values match, set ThisDay to 1.
                                Otherwise, the value will remain 0 until the correct day of the week is found.
                            --->
                                <cfif ThisDay IS 0>
                                    <cfif DayOfWeek(ThisMonthYear) IS LoopDay>
                                        <cfset ThisDay = 1>
                                    </cfif>
                                </cfif>
                            <!---
                                If the ThisDay value is still 0, or is greater than the number of days in the month, display nothing in the column. Otherwise, dispplay
                                the day of the mnth and increment the value.
                            --->
                                    <cfif (ThisDay IS NOT 0) AND (ThisDay LTE Days)>
                                    <cfoutput>
                                    <!--- I choose to highlight the current day of the year using an IF-ELSE. --->
                                        <cfif (#ThisDay# EQ #currentday#) AND (#month# EQ #startmonth#) AND (#year# EQ #startyear#)>
                                            <td align = "center" bgcolor="##FFFF99">
                                                <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
            <font class = "calendartoday">#ThisDay#</font>
                                            </td>
                                        <cfelse>
                                            <td align = "center">
                                                <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
            <font class = "calendar">#ThisDay#</font>
                                            </td>
                                        </cfif>
                                    </cfoutput>
                                    <cfset ThisDay = ThisDay + 1>
                                    <cfelse>
                                        <td></td>
                                </cfif>
                            </cfloop>
                            </tr>
                    </cfloop>
                    </table>
                </td>
            </tr>
        </table>

Similar Messages

  • Query WHERE statement to compare db record date

    Hello
    I can't get this where statement to work. I have it now so it is not throwing any errors, but it also isn't doing what it is supposed to.
    I am trying to match records date in my table with the actual calendar date, if there is a match, my cfif will take that match, and make it a link in the proper date. (it is a small calendar with the month, and the days of week with dates, each date will be normal, accept if there is a record for that date, it makes a link.
    This is my code, like I said, It doesn't throw an error, but it is not working either.
    My Query:
    <cfquery name="CaleventRec" datasource="#APPLICATION.dataSource#">
    SELECT events.eventDate, events.ID AS ID
    FROM events
    WHERE eventDate >= #CreateODBCDate("07/12/2005")# AND eventDate = #Days#
    </cfquery>
    This is the cfif statement:
    <cfoutput query="CaleventRec">
    <cfif Days EQ '#eventdate#'>
    <a href = "detail.cfm?id=#ID#">#Days#</a>
    </cfif>
    </cfoutput>
    this is all the code together:
    <cfquery name="CaleventRec" datasource="#APPLICATION.dataSource#">
    SELECT events.eventDate, events.ID AS ID
    FROM events
    WHERE eventDate >= #CreateODBCDate("07/12/2005")# AND eventDate = #Days#
    </cfquery>
                            <!--- Set the ThisDay variable to 0. This value will remain 0 until the day of the week on which the first day of the month falls on is reached. --->
                            <cfset ThisDay = 0>
                            <!--- Loop through until the number of days in the month is reached. --->
                            <cfloop condition = "ThisDay LTE Days">
                                <tr>
                                <!--- Loop though each day of the week. --->
                                <cfloop from = "1" to = "7" index = "LoopDay">
                                <!--- This turns each day into a hyperlink if it is a current or future date --->
                                   <cfoutput query="CaleventRec">
              <cfif Days EQ '#eventdate#'>
                                   <a href = "detail.cfm?id=#ID#">#Days#</a>
                                   </cfif>
              </cfoutput>
                                <!---
                                    If ThisDay is still 0, check to see if the current day of the week in the loop matches the day of the week for the first day of the month.
                                    If the values match, set ThisDay to 1.
                                    Otherwise, the value will remain 0 until the correct day of the week is found.
                                --->
                                    <cfif ThisDay IS 0>
                                        <cfif DayOfWeek(ThisMonthYear) IS LoopDay>
                                            <cfset ThisDay = 1>
                                        </cfif>
                                    </cfif>
                                <!---
                                    If the ThisDay value is still 0, or is greater than the number of days in the month, display nothing in the column. Otherwise, dispplay
                                    the day of the mnth and increment the value.
                                --->
                                        <cfif (ThisDay IS NOT 0) AND (ThisDay LTE Days)>
                                        <cfoutput>
                                        <!--- I choose to highlight the current day of the year using an IF-ELSE. --->
                                            <cfif (#ThisDay# EQ #currentday#) AND (#month# EQ #startmonth#) AND (#year# EQ #startyear#)>
                                                <td align = "center" bgcolor="##FFFF99">
                                                    <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
                                                    <font class = "calendartoday">#ThisDay#</font>
                                                </td>
                                            <cfelse>
                                                <td align = "center">
                                                    <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
                                                    <font class = "calendar">#ThisDay#</font>
                                                </td>
                                            </cfif>
                                        </cfoutput>
                                        <cfset ThisDay = ThisDay + 1>
                                        <cfelse>
                                            <td></td>
                                    </cfif>
                                </cfloop>
                                </tr>
                        </cfloop>
    I know my where statement is incorrect, I am also not sure if my cfif statement is correct either. Can anyone help me figure this out?
    thank you!
    CFmonger

    All the rest of the code works. The only part of this that doesn't work is the trying to make a link part.
    Let me  show you where I am, and what I did, then maybe you will see I am closer to the solution... I think. I made this calendar so you can cycle through the months. So if you are looking at June, you see Sun - Sat and the dates for each day of the week in the month of june. You can then choose to click the next button that will bring up the month of july, and you can keep on going as long as you want.
    That is one function and it working as of right now. This Calendar also shows what day of the week we are on. If it is June 16th then June 16 is yellow. This also works.NOw, what I need to do it to have my query, not only filter out the records for the month, (if we are in June, then the Query separates out the records for June, the date in my DB is set to mm/dd/yyyy) This query also needs to match it to a number, the days of the month. So, if there is a record on the 25th of June, then the 25th of June will be a link to another page using it's ID in the address line. If you go to July and there are lets say 3 records for that month, then all 3 dates will become a link to the same other page using it's ID in the url.
    This is what I have now. I tied the Query into the next / prev function so it filters the month, so far it seems to work, I can do a cfdump up to the point of my cfif statement and get the proper number from the date, my cfif is not firing so If I do a dump after it, it doesn't dump anyhting.
    I will post JUST the query code, then post the whole calander code so you can see it all together.
    The Query / link code:
    <!--- This is part of the next / prev nav to cycle through the months --->
    <cfset NextMonthYear = DateAdd('m', 1, ThisMonthYear)>
    <cfset NextMonth = DatePart('m', NextMonthYear)>
    <!--- My Query --->
    <cfquery name="CaleventRec" datasource="#APPLICATION.dataSource#">
    SELECT events.eventDate, events.ID AS ID
    FROM events
    WHERE eventDate Between #NextMonthYear# and #NextMonth#
    </cfquery>
    <!--- my output / cfif stement --->
    <cfoutput query="CaleventRec">
    <cfset comparison = DateCompare('#dateFormat(eventDate, 'dd')#', '#Days#', 'd')>
    <!--- When I do a cfdump here, I get the number of the first record with a day date in the DB for the month of june
    <cfdump var="#dateFormat(eventDate, 'dd')#">
                                   <cfabort>--->
    <cfif #Days# EQ ('#dateFormat(eventDate, 'dd')#')>
    <!--- When I do a dump here, I do not get anyhting, no numbers it doesn't fire
    <cfdump var="#eventDate#">
    <cfabort>--->
    <a href = "detail.cfm?id=#ID#">#Days#</a>
    </cfif>
    </cfoutput>
    ok, now that is the part to stream in the DB info into the calander.
    Here is all the code, like I said, it all works, just not making each day a link that has a record in the DB.
    <!--- Declaration of the variables --->
           <cfparam name = "month" default = "#DatePart('m', Now())#">
    <cfparam name = "year" default = "#DatePart('yyyy', Now())#">
    <cfparam name = "currentday" default = "#DatePart('d', Now())#">
    <cfparam name = "startmonth" default = "#DatePart('m', Now())#">
    <cfparam name = "startyear" default = "#DatePart('yyyy', Now())#">
    <!--- Set a requested (or current) month/year date and determine the number of days in the month. --->
    <cfset ThisMonthYear = CreateDate(year, month, '1')>
    <cfset Days = DaysInMonth(ThisMonthYear)>
    <!--- Set the values for the previous and next months for the back/next links.--->
    <cfset LastMonthYear = DateAdd('m', -1, ThisMonthYear)>
    <cfset LastMonth = DatePart('m', LastMonthYear)>
    <cfset LastYear = DatePart('yyyy', LastMonthYear)>
    <cfset NextMonthYear = DateAdd('m', 1, ThisMonthYear)>
    <cfset NextMonth = DatePart('m', NextMonthYear)>
    <cfset NextYear = DatePart('yyyy', NextMonthYear)>
    <cfset PreviousDay = DateAdd('d', -1, ThisMonthYear)>
    <cfset CurrentYear = DatePart('yyyy', Now())>
    <table border="0" width="100%" bgcolor ="#ffffff">
                <tr>
                    <td align = "center" valign="top">
                        <table border="0" width="100%" height="100%">
       <tr>
          <th align="center" colspan="7" bgcolor="#2b4e6e">
       <cfoutput>
       <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="15%" align="left" valign="middle">
      <cfif (LastYear lt CurrentYear) OR (LastYear lte CurrentYear AND LastMonth lt startmonth)>
    <cfelse>
      <a href ="index.cfm?month=#LastMonth#&year=#LastYear#" class="calNav">Prev</a></cfif></td>
            <td width="72%" align="center" valign="middle"><FONT SIZE="3" face="Arial, Helvetica, sans-serif" color="##ffffff">#MonthAsString(month)# #year#</FONT></td>
            <td width="13%" align="right" valign="middle">
      <cfif (NextYear lt CurrentYear) OR (NextYear lte CurrentYear AND NextMonth lt startmonth)>
    <cfelse>
    <a href = "index.cfm?month=#NextMonth#&year=#NextYear#" class="calNav">Next</a>  </cfif></td>
          </tr>
        </table></cfoutput></th>
       </tr>
       <tr>
        <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Sun</FONT></td>
        <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Mon</FONT></td>
        <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Tue</FONT></td>
        <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Wed</FONT></td>
        <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Thu</FONT></td>
        <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Fri</FONT></td>
        <td><FONT SIZE="2" face="Arial, Helvetica, sans-serif" color="#333366">Sat</FONT></td>
       </tr>
    <cfquery name="CaleventRec" datasource="#APPLICATION.dataSource#">
    SELECT events.eventDate, events.ID AS ID
    FROM events
    WHERE eventDate Between #NextMonthYear# and #NextMonth#
    </cfquery>
                            <!--- Set the ThisDay variable to 0. This value will remain 0 until the day of the week on which the first day of the month falls on is reached. --->
                            <cfset ThisDay = 0>
                            <!--- Loop through until the number of days in the month is reached. --->
                            <cfloop condition = "ThisDay LTE Days">
                                <tr>
                                <!--- Loop though each day of the week. --->
                                <cfloop from = "1" to = "7" index = "LoopDay">
                                <!--- This turns each day into a hyperlink if it is a current or future date --->
             <cfoutput query="CaleventRec">
             <cfset comparison = DateCompare('#dateFormat(eventDate, 'dd')#', '#Days#', 'd')>
              <cfdump var="#dateFormat(eventDate, 'dd')#">
                                   <cfabort>
              <cfif #Days# EQ ('#dateFormat(eventDate, 'dd')#')>
              <cfdump var="#eventDate#">
                                   <cfabort>
                                   <a href = "detail.cfm?id=#ID#">#Days#</a>
                                   </cfif>
              </cfoutput>
                                <!---
                                    If ThisDay is still 0, check to see if the current day of the week in the loop matches the day of the week for the first day of the month.
                                    If the values match, set ThisDay to 1.
                                    Otherwise, the value will remain 0 until the correct day of the week is found.
                                --->
                                    <cfif ThisDay IS 0>
                                        <cfif DayOfWeek(ThisMonthYear) IS LoopDay>
                                            <cfset ThisDay = 1>
                                        </cfif>
                                    </cfif>
                                <!---
                                    If the ThisDay value is still 0, or is greater than the number of days in the month, display nothing in the column. Otherwise, dispplay
                                    the day of the mnth and increment the value.
                                --->
                                        <cfif (ThisDay IS NOT 0) AND (ThisDay LTE Days)>
                                        <cfoutput>
                                        <!--- I choose to highlight the current day of the year using an IF-ELSE. --->
                                            <cfif (#ThisDay# EQ #currentday#) AND (#month# EQ #startmonth#) AND (#year# EQ #startyear#)>
                                                <td align = "center" bgcolor="##FFFF99">
                                                    <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
                <font class = "calendartoday">#ThisDay#</font>
                                                </td>
                                            <cfelse>
                                                <td align = "center">
                                                    <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
                <font class = "calendar">#ThisDay#</font>
                                                </td>
                                            </cfif>
                                        </cfoutput>
                                        <cfset ThisDay = ThisDay + 1>
                                        <cfelse>
                                            <td></td>
                                    </cfif>
                                </cfloop>
                                </tr>
                        </cfloop>
                        </table>
                    </td>
                </tr>
            </table>
    It is kind of complicated and this is why I need help. Maybe I am wrong in the variables I am pulling, but like I say in my comments, so far I pulled the day part of the month I am in out of the records up until my cfif stement.Can this be done with what I have done so far? No need to rewrite the whole calander, just the part with the query if I miss what you are saying.

  • Problem In Update Statement In Multiple Record Data Block

    Hi Friends,
    I have problem in update Statement for updating the record in multiple record data Block.
    I have two data Block the master block is single Record block and the 2nd data block is Multiple Record data Block.
    I am inserting the fields like category,and post_no for partiular job in single data block
    Now in second Multiple Record Data Block,i am inserting the multiple record for above fileds like no. of employees work in the position
    There is no problem in INSERT Statement as it is inerting all record But whenever i want to update particular Record (in Multiple Block) of employee for that category and Post_no
    then its updating all the record.
    my code is Bellow,
    IF v_count <> 0 THEN
    LOOP
    IF :SYSTEM.last_record <> 'TRUE' THEN
    UPDATE post_history
    SET idcode = :POST_HISTORY_MULTIPLE.idcode,
    joining_post_dt = :POST_HISTORY_MULTIPLE.joining_post_dt,
    leaving_post_dt = :POST_HISTORY_MULTIPLE.leaving_post_dt,
    entry_gp_stage = :POST_HISTORY_MULTIPLE.entry_gp_stage
    WHERE post_no = :POST_HISTORY_SINGLE.post_no
    AND category = :POST_HISTORY_SINGLE.category
    AND roster_no = :POST_HISTORY_SINGLE.roster_no;
    AND idcode = :POST_HISTORY_MULTIPLE.idcode;
    IF SQL%NOTFOUND THEN
    INSERT INTO post_history(post_no,roster_no,category,idcode,joining_post_dt,leaving_post_dt,entry_gp_stage)
    VALUES(g_post_no, g_roster_no, g_category, :POST_HISTORY_MULTIPLE.idcode, :POST_HISTORY_MULTIPLE.joining_post_dt,
    :POST_HISTORY_MULTIPLE.leaving_post_dt,:POST_HISTORY_MULTIPLE.entry_gp_stage);
    END IF;
    next_record;
    ELSIF :SYSTEM.last_record = 'TRUE' THEN
    UPDATE post_history
    SET idcode = :POST_HISTORY_MULTIPLE.idcode,
    joining_post_dt = :POST_HISTORY_MULTIPLE.joining_post_dt,
    leaving_post_dt = :POST_HISTORY_MULTIPLE.leaving_post_dt,
    entry_gp_stage = :POST_HISTORY_MULTIPLE.entry_gp_stage
    WHERE post_no = :POST_HISTORY_SINGLE.post_no
    AND category = :POST_HISTORY_SINGLE.category
    AND roster_no = :POST_HISTORY_SINGLE.roster_no;
    AND idcode = :POST_HISTORY_MULTIPLE.idcode;
    IF SQL%NOTFOUND THEN
    INSERT INTO post_history(post_no,roster_no,category,idcode,joining_post_dt,leaving_post_dt,entry_gp_stage)
         VALUES (g_post_no,g_roster_no,g_category,:POST_HISTORY_MULTIPLE.idcode,
              :POST_HISTORY_MULTIPLE.joining_post_dt,:POST_HISTORY_MULTIPLE.leaving_post_dt,:POST_HISTORY_MULTIPLE.entry_gp_stage);
    END IF;
    EXIT;
    END IF;
    END LOOP;
    SET_ALERT_PROPERTY('user_alert',ALERT_MESSAGE_TEXT, 'Record Updated successfuly' );
    v_button_no := SHOW_ALERT('user_alert');
    FORMS_DDL('COMMIT');
    CLEAR_FORM(no_validate);
    Please Guide me
    Thanks in advence

    UPDATE post_history
    SET idcode = :POST_HISTORY_MULTIPLE.idcode,
    joining_post_dt = :POST_HISTORY_MULTIPLE.joining_post_dt,
    leaving_post_dt = :POST_HISTORY_MULTIPLE.leaving_post_dt,
    entry_gp_stage = :POST_HISTORY_MULTIPLE.entry_gp_stage
    WHERE post_no = :POST_HISTORY_SINGLE.post_no
    AND category = :POST_HISTORY_SINGLE.category
    AND roster_no = :POST_HISTORY_SINGLE.roster_no;
    AND idcode = :POST_HISTORY_MULTIPLE.idcode;
    UPDATE post_history
    SET idcode = :POST_HISTORY_MULTIPLE.idcode,
    joining_post_dt = :POST_HISTORY_MULTIPLE.joining_post_dt,
    leaving_post_dt = :POST_HISTORY_MULTIPLE.leaving_post_dt,
    entry_gp_stage = :POST_HISTORY_MULTIPLE.entry_gp_stage
    WHERE post_no = :POST_HISTORY_SINGLE.post_no
    AND category = :POST_HISTORY_SINGLE.category
    AND roster_no = :POST_HISTORY_SINGLE.roster_no;
    AND idcode = :POST_HISTORY_MULTIPLE.idcode;These update statements are without where clause, so it will update all records.
    If it is specific to oracle forms then u may get better help at Forms section.

  • Writing single query with conflicting WHERE statements

    How do I run the following as a single query that will result in a column that pertains to the first block of code and then another column that pertains to the 2nd block of code? The issue is that I need 2 different WHERE statements. So the final output will be patient_id, complete, incomplete.
    SELECT patient_id, COUNT(*) AS complete
    FROM STATUS
    WHERE status = 1
    GROUP BY patient_id
    ORDER BY patient_id;
    SELECT patient_id, COUNT(*) AS incomplete
    FROM STATUS
    WHERE status = 2
    GROUP BY patient_id
    ORDER BY patient_id;
    Thanks!

    Hi,
    apex wrote:
    Thanks for all of the help.
    I would like to add another column with decile and am struggling as to how to do it. Since I can't reference something in a calculation in the same step, I think I will need a 3rd nesting, but what I haven't figured out is how to get the number of subjects whose ratio is less than that subject's ratio. Right: you can't assign an alias (such as complete or ratio) to a calculated column and use that alias in the same sub-query.
    If the calculation isn't very complicated, then you might find it simpler just to repeat the calculation. For example, I think this is what you want:
    WITH     got_complete     AS
         SELECT    patient_id
         ,        COUNT ( CASE WHEN status = 1 THEN 1 END )     AS complete
         ,       COUNT ( CASE WHEN status = 2 THEN 1 END )      AS incomplete
         FROM        pt_status
         WHERE        status IN (1,2)
         GROUP BY  patient_id
    SELECT       patient_id, complete, incomplete
    ,                                complete / (complete + incomplete)     AS Ratio
    ,       RANK () OVER ( ORDER BY  complete / (complete + incomplete) ) - 1
                                                        AS decile
    FROM      got_complete
    ORDER BY  complete
    ,            incomplete     DESC
    ;RANK numbers rows 1, 2, 3, ... If I understand your requirements, you want the numbering to start with 0 (meaning "there are 0 other patients with a lower ratio"), so that's why I subtracted 1.
    Depending how you want to handle ties, you may need to add some tie-breaker expressions to the analytic ORDER BY clause, and/or use ROW_NUMBER instead of RANK.
    Here, I used the calculation "complete / (complete + incomplete)" in the ratio column, then repeated it in the decile column.
    I you want, you can add another sub-query, called got_ratio, which would add the ratio column, but do nothing about the decile column. Then, in the main query, you could use RANK as shown above (or, as you suggested, a scalar sub-query referencing got_ratio) to get the number of other pateient_ids with lower ratios.
    On the other hand, you could do this whole job without any sub-queries, using AVG as I did earlier, and then repeating that same AVG expression in the ORDER BY clause for RANK. Aggregate functions are computed before analytic fucntions, so the analytic RANK can referenece the aggregate AVG.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. Include examples of decile ties (2 or more patients with the same ratio).
    Explain, using specific examples, how you get those results from that data.

  • Pre query , post query where date = mon-yyyy

    I have a tabular block B2 with many records
    this block items are vouhcerno, voucherdate. voucherno number(6) and voucherdate date.
    when new form instance i execute query it shows me all the records working fine.
    I add one list item here when new form instance this list item got record like
    Jan-2009
    Feb-2009
    Mar-2009
    so on...
    I want that when i select Jan-2009 from list item and press button
    block B2 only show my January 2009 records.
    I tried to this in pre query and also post query trigger but not successful.
    Kindly guide me .

    Arun really tnx, you are helping me.
    I m sorry Your this code also not working.
    i want to add one more condition in this code
    SET_BLOCK_PROPERTY('b2',DEFAULT_WHERE, 'to_char(voucherdate,''fmmon-fmYyyy'')= ''' || Lower(:vdate ) || ''''  );
    And :vtype = "PV'
    {code}
    I m using this
    {code}
    SET_BLOCK_PROPERTY('b2',DEFAULT_WHERE, 'to_char(voucherdate,''fmmon-fmYyyy'')= ''' || Lower(:vdate ) || 'and :B2.vtype = PV'|| ''''  );
    {code}
    but Not return query.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • SQL Where clause when comparing dates and times in ASP

    Hello,
    I am trying to pull data from my database which is dependant on both the date and time in HH24 format. So, my where clause looks something like this:
    select * from thisTable where activity_time >= myCurrentDate
    (myCurrentDate is a variable that is built which gives it the following format DD-MON-YYYY HH24:MI:SS)
    So, the actual passed string to my call is:
    select * from thisTable where ACTIVITY_TIME >= '02-DEC-2008 18:22:00' order by ACTIVITY_TIME asc
    However, when calling this, I get the famous "ORA-01830: date format picture ends before converting entire input string"
    Can anyone please help me?!?!?!?
    Thanks in advance

    Enrique answered your immediate question, but I'd like to point up a broader issue, and that is that you should <b><u>always</u></b> use the TO_DATE and TO_CHAR functions at the sql statement level when working with date datatypes. That way you are never dependent on some default over which you have no control. I call that is 'defensive coding'.

  • Filter data using where statement : need to filter a variable if it starts

    Hi,
    in my loop statment , i am using a where condition.
    a variable has numbers and characters , i want to filter the variable using where statement identifying if it is acharacter not to enter into the loop.
    any suggestions . Thanks in advance.
    regards,
    Ry

    Hi ,
    try like this
    data:l_file_data(20) type c,
    oref   TYPE REF TO cx_root.
    data: l_amount type p decimals 2.
    l_file_data = '12A3'.
    try.
    l_amount = l_file_data.
    catch cx_root into oref.
    endtry.
    if oref is not initial.
    write: 'Miss Match'.
    endif.
    regards
    Prabhu

  • Help understanding WHERE statement.

    Hey you guys,
    I'm a complete newbie and have been studying Oracle SQL 11 Fundamentals book.
    On chapter 5 lab I ran into something I would like some explanation or clarification as of why is needed.
    Basically is asking to query the OE schema to find all employees whose birthdays occur between
    two days ago and seven days from now and based on that display some descriptive messages...
    select cust_first_name, cust_last_name, cust_email, date_of_birth,
    case to_number(to_char(date_of_birth, 'DD')) - to_number(to_char(sysdate, 'DD'))
      when -2 then 'Day before yesterday'
      when -1 then 'Yesterday'
      when  0 then 'Today'
      when  1 then 'Tomorrow'
      when  2 then 'Day after tomorrow'
      else 'Later this week'
    END BIRTHDAY
    from customers
    where to_char(date_of_birth, 'MON')= to_char(sysdate, 'MON')
    and to_number(to_char(date_of_birth, 'DD')) - to_number(to_char(sysdate, 'DD')) between -2 and 7
    order by to_char(date_of_birth, 'MMDD');
    I'm referring to the first condition in the where clause.
    Line 11 to_char(date_of_birth, 'MON')= to_char(sysdate, 'MON')
    Where I would like clarification is in the first clause of the where statement. Can someone explain why is needed?
    I feel like the second clause is enough to filter for the required task but when ran with just second where clause
    I get a different number of records.
    The first where clause compares that the birthday month of each employees is equal to the sysdate, how is that relevant?
    What if the current sysdate is 01-DEC-13 and some of the employees birthday is in Nov. How would that affect my result.
    Regards.

    I will assume person born Feb 29 celebrates birthday Feb 28 if current year isn't a leap year and Feb29 if it is a leap year. Then all we need to do is calculate birtday this year using ADD_MONTHS:
    with t as (
               select  cust_first_name,
                       cust_last_name,
                       date_of_birth,
                       add_months(date_of_birth,12 * (to_char(sysdate,'yyyy') - to_char(date_of_birth,'yyyy'))) date_of_birth_this_year
                 from  oe.customers
    SELECT  cust_first_name,
            cust_last_name,
            date_of_birth,
            case date_of_birth_this_year - trunc(sysdate)
              when -2 THEN 'Day before yesterday'
              when -1 THEN 'Yesterday'
              when  0 THEN 'Today'
              when  1 THEN 'Tomorrow'
              when  2 THEN 'Day after tomorrow'
              else 'In ' || (date_of_birth_this_year - trunc(sysdate)) || ' days'
            end birthday
      from  t
      where date_of_birth_this_year - trunc(sysdate) between -2 and 10
      order by date_of_birth_this_year - trunc(sysdate)
    CUST_FIRST_NAME      CUST_LAST_NAME       DATE_OF_B BIRTHDAY
    Danny                Wright               20-DEC-48 Day before yesterday
    Kiefer               Reynolds             21-DEC-53 Yesterday
    Maximilian           Henner               21-DEC-73 Yesterday
    Bo                   Ashby                21-DEC-56 Yesterday
    Shah Rukh            Field                25-DEC-57 In 3 days
    Rufus                Belushi              26-DEC-52 In 4 days
    Diane                Higgins              26-DEC-84 In 4 days
    Fritz                Hackman              26-DEC-83 In 4 days
    Danny                Rourke               31-DEC-47 In 9 days
    Grace                Dvrrie               31-DEC-48 In 9 days
    10 rows selected.
    SQL>
    And to mimic Feb 28 & 29 leap year:
    SQL> with t as (
      2             select  cust_first_name,
      3                     cust_last_name,
      4                     date_of_birth,
      5                     add_months(date_of_birth,12 * (to_char(date '2016-02-29','yyyy') - to_char(date_of_birth,'yyyy'))) date_of_birth_this_year
      6               from  oe.customers
      7            )
      8  SELECT  cust_first_name,
      9          cust_last_name,
    10          date_of_birth,
    11          case date_of_birth_this_year - trunc(date '2016-02-29')
    12            when -2 THEN 'Day before yesterday'
    13            when -1 THEN 'Yesterday'
    14            when  0 THEN 'Today'
    15            when  1 THEN 'Tomorrow'
    16            when  2 THEN 'Day after tomorrow'
    17            else 'In ' || (date_of_birth_this_year - trunc(date '2016-02-29')) || ' days'
    18          end birthday
    19    from  t
    20    where date_of_birth_this_year - trunc(date '2016-02-29') between -2 and 10
    21    order by date_of_birth_this_year - trunc(date '2016-02-29')
    22  /
    CUST_FIRST_NAME      CUST_LAST_NAME       DATE_OF_B BIRTHDAY
    Maureen              Sanders              29-FEB-24 Today
    Kris                 Curtis               02-MAR-55 Day after tomorrow
    Rob                  Russell              02-MAR-77 Day after tomorrow
    Harrison             Pacino               02-MAR-53 Day after tomorrow
    Keir                 Chandar              04-MAR-60 In 4 days
    Gerard               Hershey              06-MAR-48 In 6 days
    Sharmila             Fonda                06-MAR-49 In 6 days
    Luchino              Jordan               06-MAR-83 In 6 days
    Dom                  Hoskins              10-MAR-51 In 10 days
    Bruce                Hulce                10-MAR-72 In 10 days
    10 rows selected.
    SQL> with t as (
      2             select  cust_first_name,
      3                     cust_last_name,
      4                     date_of_birth,
      5                     add_months(date_of_birth,12 * (to_char(date '2016-02-28','yyyy') - to_char(date_of_birth,'yyyy'))) date_of_birth_this_year
      6               from  oe.customers
      7            )
      8  SELECT  cust_first_name,
      9          cust_last_name,
    10          date_of_birth,
    11          case date_of_birth_this_year - trunc(date '2016-02-28')
    12            when -2 THEN 'Day before yesterday'
    13            when -1 THEN 'Yesterday'
    14            when  0 THEN 'Today'
    15            when  1 THEN 'Tomorrow'
    16            when  2 THEN 'Day after tomorrow'
    17            else 'In ' || (date_of_birth_this_year - trunc(date '2016-02-28')) || ' days'
    18          end birthday
    19    from  t
    20    where date_of_birth_this_year - trunc(date '2016-02-28') between -2 and 10
    21    order by date_of_birth_this_year - trunc(date '2016-02-28')
    22  /
    CUST_FIRST_NAME      CUST_LAST_NAME       DATE_OF_B BIRTHDAY
    Maureen              Sanders              29-FEB-24 Tomorrow
    Rob                  Russell              02-MAR-77 In 3 days
    Harrison             Pacino               02-MAR-53 In 3 days
    Kris                 Curtis               02-MAR-55 In 3 days
    Keir                 Chandar              04-MAR-60 In 5 days
    Sharmila             Fonda                06-MAR-49 In 7 days
    Luchino              Jordan               06-MAR-83 In 7 days
    Gerard               Hershey              06-MAR-48 In 7 days
    8 rows selected.
    SQL>
    And to mimic Feb 28 non-leap year:
    SQL> with t as (
      2             select  cust_first_name,
      3                     cust_last_name,
      4                     date_of_birth,
      5                     add_months(date_of_birth,12 * (to_char(date '2014-02-28','yyyy') - to_char(date_of_birth,'yyyy'))) date_of_birth_this_year
      6               from  oe.customers
      7            )
      8  SELECT  cust_first_name,
      9          cust_last_name,
    10          date_of_birth,
    11          case date_of_birth_this_year - trunc(date '2014-02-28')
    12            when -2 THEN 'Day before yesterday'
    13            when -1 THEN 'Yesterday'
    14            when  0 THEN 'Today'
    15            when  1 THEN 'Tomorrow'
    16            when  2 THEN 'Day after tomorrow'
    17            else 'In ' || (date_of_birth_this_year - trunc(date '2014-02-28')) || ' days'
    18          end birthday
    19    from  t
    20    where date_of_birth_this_year - trunc(date '2014-02-28') between -2 and 10
    21    order by date_of_birth_this_year - trunc(date '2014-02-28')
    22  /
    CUST_FIRST_NAME      CUST_LAST_NAME       DATE_OF_B BIRTHDAY
    Maureen              Sanders              29-FEB-24 Today
    Kris                 Curtis               02-MAR-55 Day after tomorrow
    Rob                  Russell              02-MAR-77 Day after tomorrow
    Harrison             Pacino               02-MAR-53 Day after tomorrow
    Keir                 Chandar              04-MAR-60 In 4 days
    Gerard               Hershey              06-MAR-48 In 6 days
    Sharmila             Fonda                06-MAR-49 In 6 days
    Luchino              Jordan               06-MAR-83 In 6 days
    Dom                  Hoskins              10-MAR-51 In 10 days
    Bruce                Hulce                10-MAR-72 In 10 days
    10 rows selected.
    SQL>
    SY.

  • Query taking long time for EXTRACTING the data more than 24 hours

    Hi ,
    Query taking long time for EXTRACTING the data more than 24 hours please find the query and explain plan details below even indexes avilable on table's goe's to FULL TABLE SCAN. please suggest me.......
    SQL> explain plan for select a.account_id,round(a.account_balance,2) account_balance,
    2 nvl(ah.invoice_id,ah.adjustment_id) transaction_id,
    to_char(ah.effective_start_date,'DD-MON-YYYY') transaction_date,
    to_char(nvl(i.payment_due_date,
    to_date('30-12-9999','dd-mm-yyyy')),'DD-MON-YYYY')
    due_date, ah.current_balance-ah.previous_balance amount,
    decode(ah.invoice_id,null,'A','I') transaction_type
    3 4 5 6 7 8 from account a,account_history ah,invoice i_+
    where a.account_id=ah.account_id
    and a.account_type_id=1000002
    and round(a.account_balance,2) > 0
    and (ah.invoice_id is not null or ah.adjustment_id is not null)
    and ah.CURRENT_BALANCE > ah.previous_balance
    and ah.invoice_id=i.invoice_id(+)
    AND a.account_balance > 0
    order by a.account_id,ah.effective_start_date desc; 9 10 11 12 13 14 15 16
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)|
    | 0 | SELECT STATEMENT | | 544K| 30M| | 693K (20)|
    | 1 | SORT ORDER BY | | 544K| 30M| 75M| 693K (20)|
    |* 2 | HASH JOIN | | 544K| 30M| | 689K (20)|
    |* 3 | TABLE ACCESS FULL | ACCOUNT | 20080 | 294K| | 6220 (18)|
    |* 4 | HASH JOIN OUTER | | 131M| 5532M| 5155M| 678K (20)|
    |* 5 | TABLE ACCESS FULL| ACCOUNT_HISTORY | 131M| 3646M| | 197K (25)|
    | 6 | TABLE ACCESS FULL| INVOICE | 262M| 3758M| | 306K (18)|
    Predicate Information (identified by operation id):
    2 - access("A"."ACCOUNT_ID"="AH"."ACCOUNT_ID")
    3 - filter("A"."ACCOUNT_TYPE_ID"=1000002 AND "A"."ACCOUNT_BALANCE">0 AND
    ROUND("A"."ACCOUNT_BALANCE",2)>0)
    4 - access("AH"."INVOICE_ID"="I"."INVOICE_ID"(+))
    5 - filter("AH"."CURRENT_BALANCE">"AH"."PREVIOUS_BALANCE" AND ("AH"."INVOICE_ID"
    IS NOT NULL OR "AH"."ADJUSTMENT_ID" IS NOT NULL))
    22 rows selected.
    Index Details:+_
    SQL> select INDEX_OWNER,INDEX_NAME,COLUMN_NAME,TABLE_NAME from dba_ind_columns where
    2 table_name in ('INVOICE','ACCOUNT','ACCOUNT_HISTORY') order by 4;
    INDEX_OWNER INDEX_NAME COLUMN_NAME TABLE_NAME
    OPS$SVM_SRV4 P_ACCOUNT ACCOUNT_ID ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT_NAME ACCOUNT_NAME ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT CUSTOMER_NODE_ID ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT ACCOUNT_TYPE_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_ACCOUNT_TYPE ACCOUNT_TYPE_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_INVOICE INVOICE_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_PREVIOUS_INVOICE PREVIOUS_INVOICE_ID ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT_NAME_ID ACCOUNT_NAME ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT_NAME_ID ACCOUNT_ID ACCOUNT
    OPS$SVM_SRV4 I_LAST_MODIFIED_ACCOUNT LAST_MODIFIED ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_INVOICE_ACCOUNT INVOICE_ACCOUNT_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ACCOUNT ACCOUNT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ACCOUNT SEQNR ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_INVOICE INVOICE_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ADINV INVOICE_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA CURRENT_BALANCE ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA INVOICE_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA ADJUSTMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA ACCOUNT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_LMOD LAST_MODIFIED ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ADINV ADJUSTMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_PAYMENT PAYMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ADJUSTMENT ADJUSTMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_APPLIED_DT APPLIED_DATE ACCOUNT_HISTORY
    OPS$SVM_SRV4 P_INVOICE INVOICE_ID INVOICE
    OPS$SVM_SRV4 U_INVOICE CUSTOMER_INVOICE_STR INVOICE
    OPS$SVM_SRV4 I_LAST_MODIFIED_INVOICE LAST_MODIFIED INVOICE
    OPS$SVM_SRV4 U_INVOICE_ACCOUNT ACCOUNT_ID INVOICE
    OPS$SVM_SRV4 U_INVOICE_ACCOUNT BILL_RUN_ID INVOICE
    OPS$SVM_SRV4 I_INVOICE_BILL_RUN BILL_RUN_ID INVOICE
    OPS$SVM_SRV4 I_INVOICE_INVOICE_TYPE INVOICE_TYPE_ID INVOICE
    OPS$SVM_SRV4 I_INVOICE_CUSTOMER_NODE CUSTOMER_NODE_ID INVOICE
    32 rows selected.
    Regards,
    Bathula
    Oracle-DBA

    I have some suggestions. But first, you realize that you have some redundant indexes, right? You have an index on account(account_name) and also account(account_name, account_id), and also account_history(invoice_id) and account_history(invoice_id, adjustment_id). No matter, I will suggest some new composite indexes.
    Also, you do not need two lines for these conditions:
    and round(a.account_balance, 2) > 0
    AND a.account_balance > 0
    You can just use: and a.account_balance >= 0.005
    So the formatted query isselect a.account_id,
           round(a.account_balance, 2) account_balance,
           nvl(ah.invoice_id, ah.adjustment_id) transaction_id,
           to_char(ah.effective_start_date, 'DD-MON-YYYY') transaction_date,
           to_char(nvl(i.payment_due_date, to_date('30-12-9999', 'dd-mm-yyyy')),
                   'DD-MON-YYYY') due_date,
           ah.current_balance - ah.previous_balance amount,
           decode(ah.invoice_id, null, 'A', 'I') transaction_type
      from account a, account_history ah, invoice i
    where a.account_id = ah.account_id
       and a.account_type_id = 1000002
       and (ah.invoice_id is not null or ah.adjustment_id is not null)
       and ah.CURRENT_BALANCE > ah.previous_balance
       and ah.invoice_id = i.invoice_id(+)
       AND a.account_balance >= .005
    order by a.account_id, ah.effective_start_date desc;You will probably want to select:
    1. From ACCOUNT first (your smaller table), for which you supply a literal on account_type_id. That should limit the accounts retrieved from ACCOUNT_HISTORY
    2. From ACCOUNT_HISTORY. We want to limit the records as much as possible on this table because of the outer join.
    3. INVOICE we want to access last because it seems to be least restricted, it is the biggest, and it has the outer join condition so it will manufacture rows to match as many rows as come back from account_history.
    Try the query above after creating the following composite indexes. The order of the columns is important:create index account_composite_i on account(account_type_id, account_balance, account_id);
    create index acct_history_comp_i on account_history(account_id, invoice_id, adjustment_id, current_balance, previous_balance, effective_start_date);
    create index invoice_composite_i on invoice(invoice_id, payment_due_date);All the columns used in the where clause will be indexed, in a logical order suited to the needs of the query. Plus each selected column is indexed as well so that we should not need to touch the tables at all to satisfy the query.
    Try the query after creating these indexes.
    A final suggestion is to try larger sort and hash area sizes and a manual workarea policy.alter session set workarea_size_policy = manual;
    alter session set sort_area_size = 2147483647;
    alter session set hash_area_size = 2147483647;

  • Xi JDBC Adapter - Query SQL Statement & Update SQL Statement

    Hi!
    I configure the JDBC adapter sender (XI) to take data from Oracle database.
    I set the Query and Update SQL Statement in the Processing parameters of the communication channel in this way:
    Query SQL Statement :
    SELECT * FROM XI_TABLE WHERE STATUS = 'WAIT' ORDER BY ROW_NUM
    Update SQL Statement :
    UPDATE XI_TABLE SET STATUS = 'DONE', DATE = SYSDATE WHERE STATUS = 'WAIT'
    My question is :
    If a new record with the field STATUS = 'WAIT' is added to the table (xi_table) during the time between the execution of the query statement and the start of the update statement, what will happen to that record during the update?
    There is a way to avoid the update of that record? or to pass to the update statement only the record selected in the query statement?
    Please, may you give me some example?
    Thanks,
    Francesco

    hi,
    did you check "Isolation Level for Transaction"
    for the sender jdbc adapter?
    http://help.sap.com/saphelp_nw04/helpdata/en/7e/5df96381ec72468a00815dd80f8b63/content.htm
    Regards,
    michal

  • Compare two records within a view

    Hi,
    I wonder if it is possible to compare two or more records within a view, and how to do it.
    Thanks in advance.

    M. Comi wrote:
    I wanted to compare two records of the view and see if they are the same or not...
    My data are as follows:
    Soglia Ingresso_CL_PF     10     10
    Downgrade MDP 3     2102     2101
    I want to check if the "downgrade" records have the same values for the second and the third column, and in this case replace the values on the second record.
    But I did it with a select on the same fields of the original tables, plus two fields obtained with lag function...
    I don't know if it is clear or not, the important is that I got what I wanted.Sorry, it's not clear.
    Are you still having a problem? If so:
    (1) Please describe the problem.
    (2) What results do you want to see from the sample data you posted?
    (3) Is the second column of
    Downgrade MDP 3 2102 2101'Downgrade', 'MDP', 3, 2102, 2101, some combination, or NULL? When posting data, the most helpful thing is to post INSERT (or CREATE TABLE AS ...) statements. The second-best thing is to post formatted data. Type &#123;code&#125; before and after sections where spacing is important, and post column headers.

  • Compare two records column by column in same table

    Hi All,
    I have an address table with ID as the PK but there can be more than one ID. I need to take the latest address record and first see if that same ID has a previous address record and if so, compare each column to see if the data has changed. I only need to compare the latest record with the next latest record.
    I cannot figure this out at all. I can of course use the MAX function to get the latest address records but do not know how I can pull the next latest address record that matches the ID and compare each column.
    Sample table:
    ID street city state zip effective_date
    1 123 main chicago IL 60111 3-7-2012
    2 34 N 13th new york NY 18374 3-7-2012
    3 15 N main Dallas TX 47389 3-7-2012
    1 89 N main chicago IL 60111 1-5-2012
    1 16 East St columbus OH 47382 12-10-2011
    2 34 N 13th new york NY 18374 10-7-2011
    2 15 S Elm new york NY 18374 09-1-2011
    3 15 N main Dallas TX 47389 10-4-2011
    SO...in the table above using today as the latest record date, based of my criteria I would only want to pull record ID 1 and 2 since the next most recent record for those IDs have had at least one of their address data change. ID 3 has exactly the same address data so I would not consider that in my criteria.
    Can i do this with SQL only or will i need to create a procedure or function?
    Any help is appreciated
    Ben

    Ben C wrote:
    Hi All,
    I have an address table with ID as the PK but there can be more than one ID. You mean there can be more than one row with tha same ID, right? (There can be more than one ID, also.)
    I need to take the latest address record and first see if that same ID has a previous address record and if so, compare each column to see if the data has changed. I only need to compare the latest record with the next latest record.
    ... Sample table:Whenever you have a problem, please post CREATE TABLE and INSERT statements for the sample data, and the exact results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    Can i do this with SQL only or will i need to create a procedure or function?You don't need PL/SQL, if I understand your requirements. You can do something like this:
    WITH     got_analytics     AS
         SELECT     id, street, city, state, zip, effective_date
         ,     COUNT (*)     OVER ( PARTITION BY  id )          AS cnt
         ,     ROW_NUMBER () OVER ( PARTITION BY  id
                                   ORDER BY          effective_date     DESC
                           )                           AS r_num
         FROM    table_x
    --     WHERE     ...     -- If you need any filtering, put it here
    SELECT    id, street, city, state, zip, effective_date
    FROM       got_analytics
    WHERE       cnt     > 1
    AND       r_num     <= 2
    ORDER BY  id
    ,            effective_date
    ;This will show the most recent 2 rows for each id that has 2 (or more) rows.
    You can modify it to only include ids where there was some change in street, city, state or zip between those 2 rows.
    WITH     got_analytics     AS
         SELECT     id, street, city, state, zip, effective_date
         ,     COUNT (*)     OVER ( PARTITION BY  id )          AS cnt
         ,     ROW_NUMBER () OVER ( PARTITION BY  id
                                   ORDER BY          effective_date     DESC
                           )                           AS r_num
         FROM    table_x
    --     WHERE     ...     -- If you need any filtering, put it here
    ,     got_unique_cnts     AS
         SELECT     id, street, city, state, zip, effective_date
         ,     COUNT (DISTINCT '~' || street) OVER (PARTITION BY id)     AS street_cnt
         ,     COUNT (DISTINCT '~' || city)   OVER (PARTITION BY id)     AS city_cnt
         ,     COUNT (DISTINCT '~' || state)  OVER (PARTITION BY id)     AS state_cnt
         ,     COUNT (DISTINCT '~' || zip)    OVER (PARTITION BY id)     AS zip_cnt
         FROM       got_analytics
         WHERE       cnt     > 1
         AND       r_num     <= 2
    SELECT    id, street, city, state, zip, effective_date
    FROM       got_unique_cnts
    WHERE       street_cnt     > 1
    OR       city_cnt     > 1
    OR       state_cnt     > 1
    OR       zip_cnt     > 1
    ORDER BY  id
    ,            effective_date
    ;This assumes that street, city, state and zip are all VARCHAR2s. If any of those columns is NULL on one row, and not NULL on the other row for that ID, that counts as a difference.
    Edited by: Frank Kulash on Mar 7, 2012 3:37 PM
    Edited by: Frank Kulash on Mar 7, 2012 3:41 PM

  • How to compare two tables data...need sql report or utility to find differe

    Hi,
    We have a requirement where we are asked to find data differences between two tables and one of the tables reside on remote database. The database version is same ( 10g ) and datatypes for the tables are similar.
    The client is looking for a sql report or kind of utility to display the data differences for each column ( if possible count differences ) with some meaningful error messages.
    Could anyone let me know the best possible way of doing it..?
    Thanks
    Hitarth

    Hi,
    I found something for tables comparison but getting one error...can you check this please and let me know what is wrong
    Here is the function:
    CREATE OR REPLACE FUNCTION compare_query_results (
    p_query1 IN VARCHAR2
    , p_query2 IN VARCHAR2
    , p_raise_error_if_not_equal IN BOOLEAN DEFAULT FALSE
    , p_raise_error_if_no_rows IN BOOLEAN DEFAULT FALSE
    RETURN NUMBER
    IS
    -- Constants
    c_query_results_equal CONSTANT PLS_INTEGER := 0;
    c_query_results_not_equal CONSTANT PLS_INTEGER := 1;
    oracr CONSTANT VARCHAR2 (1) := CHR (10);
    -- Variable Declaration
    v_sql_stmt VARCHAR2 (32767);
    v_record_count PLS_INTEGER;
    v_return_code PLS_INTEGER;
    v_record DUAL.dummy%TYPE;
    v_result_set_has_rows BOOLEAN;
    -- Ref Cursors
    v_cursor sys_refcursor;
    -- Custom Defined-Exceptions
    result_sets_do_not_match EXCEPTION;
    query_returns_no_rows EXCEPTION;
    BEGIN
    -- Get the count of differing records between p_query1 and p_query2
    dbms_output.put_line('Start-1');
    v_sql_stmt :=
    ' (SELECT /*+ materialize */'
    || SUBSTR (p_query1, INSTR (UPPER (p_query1)
    , 'SELECT'
    , 1
    , 1
    ) + 6)
    || ')
    , (SELECT /*+ materialize */'
    || SUBSTR (p_query2, INSTR (UPPER (p_query2)
    , 'SELECT'
    , 1
    , 1
    ) + 6)
    || ')
    SELECT ''X''
    FROM (
    (SELECT * FROM test1 MINUS SELECT * FROM test2)
    UNION ALL
    (SELECT * FROM test2 MINUS SELECT * FROM test1)
    dbms_output.put_line('Start-2');
    OPEN v_cursor
    FOR v_sql_stmt;
    dbms_output.put_line('Start-3');
    FETCH v_cursor
    INTO v_record;
    dbms_output.put_line('Start-4');
    v_result_set_has_rows := v_cursor%FOUND;
    dbms_output.put_line('Start-5');
    CLOSE v_cursor;
    dbms_output.put_line('Start-6');
    -- If there are rows - the result sets do NOT match...
    IF v_result_set_has_rows
    THEN
    v_return_code := c_query_results_not_equal;
    IF p_raise_error_if_not_equal
    THEN
    RAISE result_sets_do_not_match;
    END IF;
    -- If there are no rows - the result sets do match...
    ELSIF NOT v_result_set_has_rows
    THEN
    IF p_raise_error_if_no_rows
    THEN
    -- Check to make sure that the queries contain rows if desired...
    v_sql_stmt := 'SELECT ''X''
    FROM (' || oracr || p_query1 || oracr || ')';
    OPEN v_cursor
    FOR v_sql_stmt;
    FETCH v_cursor
    INTO v_record;
    IF v_cursor%NOTFOUND
    THEN
    CLOSE v_cursor;
    RAISE query_returns_no_rows;
    END IF;
    CLOSE v_cursor;
    END IF;
    v_return_code := c_query_results_equal;
    END IF;
    RETURN v_return_code;
    EXCEPTION
    WHEN result_sets_do_not_match
    THEN
    raise_application_error (-20101, 'The Queries'' result sets do NOT match. Error returned
    as requested.');
    WHEN query_returns_no_rows
    THEN
    raise_application_error (-20102, 'The Queries'' result sets match, however they contain no
    rows. Error returned as requested.');
    WHEN OTHERS
    THEN
    -- Raise the error
    raise_application_error (-20103
    , 'There is a syntax or semantical error in one or both queries
    preventing comparison.'
    || oracr
    || 'Error Stack :'
    || oracr
    || DBMS_UTILITY.format_error_stack ()
    || oracr
    || 'Error_Backtrace:'
    || oracr
    || DBMS_UTILITY.format_error_backtrace ());
    END compare_query_results;
    I have created two tables ( test1 and test2 ) with few columns and with the same datatypes and executed the above function...I am getting error as folliowing:
    DECLARE
    ERROR at line 1:
    ORA-20103: There is a syntax or semantical error in one or both queries
    preventing comparison.
    Error Stack :
    ORA-00900: invalid SQL statement
    Error_Backtrace:
    ORA-06512: at "ORAOWNER.COMPARE_QUERY_RESULTS", line 53
    ORA-06512: at "ORAOWNER.COMPARE_QUERY_RESULTS", line 121
    ORA-06512: at line 12
    Could someone please help me fixing this error..It would be really appreciated
    Thanks
    Hitarth

  • Passing a string into an SQL query IN statement

    Hello,
    I need to connect to a database to pull some data to dynamically create a form based on the data I pull back. My SQL query works fine when I manually run it through a SQL client tool, but when I try to pass it through my workflow I'm having trouble with passing my string into the IN part of the statement. So if for example my SQL query is:
    SELECT Field1, Field2, Field3 FROM Table1 WHERE Field4 IN (?)
    I have a process variable that has the string I'm trying to pass into the ?, but I don't seem to be able to get the query to run. I have tried setting up my query to run as a Parameterized Query (passing my string process variable into the ?), and by setting the query up through xPath (where I am calling my process variable with an xPath declaration), but am not having any luck.
    The process variable I am trying to pass is formatted such that I'm passing 'Value1','Value2','Value3' but I can reformat this string if need be. Even with using test data I can't get the query to return anything. For test data I have tried: 'Value1','Value2','Value3' ; Value1','Value2','Value3 ; Value1,Value2,Value3 but the query never returns any data. I can't seem to see how to format the string to pass into the query. The Query will work with a single Value in the test data, but as soon as I try to pass multiple values within the string it fails. Any suggestions?

    The problem looks to be a limit on what I can pass into the SQL query component. My string is coming from data returned from another database. I take the xml output from that database call, pass it through a set variable component to remove my xml tags from the string, and then format the string in a script component (I have to do it this way because of the way the data coming out of my first database call). I've put in loggers, and can see that the string I'm passing into my query that is giving me problems, is formatted the same way as if I were to use the concat function Scott listed above. It looks like there is a limitation on what can be passed in my variable. I have tried creating my entire SQL query statement in a set variable component, and then just calling the process variable that holds that statement, but there is a character limit of 128 character for what can be passed in a variable through xpath in the SQL query component.
    The next thing I tried was changing my SQL where clause. Instead of passing my variable directly into the IN statement I set up a PATINDEX('%:'+countyname+ ':%', ?) > 0 call to check for the values in my database call. As you can see I took out the "," that I was passing as part of my string, thinking that the SQL component was getting confused by them, and placed ":" characters around my values being passed in my string variable. No matter what I try to do though I'm not able to get the query to run. The component looks like it is taking my string, and is seeing the whole thing as a string instead of passing it as individual values within a string.
    I think I'm getting close, but I keep getting a Content not allowed in prolog exception in the server logs.

  • How to compare table's date field with dropdown year field

    Hi All,
    I have one requirement to display the selected rows from a database table based on the selection of drop down.
    Here, I have one dropdown of year(like 2009,2010,....) and I have one database table which contains one field with "DATE".
    Now, I want to compare table's DATE field with my dropdown field.
    Problem is that table's DATE field is of type "DATS" and dropdown is of type INTEGER(or) STRING ...
    How to compare this fields?
    Can any one please give me solution for this...!
    Thanks in Advance!

    Hi  sreelakshmi.B,
    try the following:
    DATA lt_dats        TYPE TABLE OF dats.
    DATA l_dat_i        TYPE          i.
    DATA l_dat_c_4(4)   TYPE          c.
    DATA l_dat_c_12(12) TYPE          c.
    DATA l_dats_from    TYPE          dats.
    DATA l_dats_to      TYPE          dats.
    *Move Date from Integer to Char
    l_dat_c_4 = l_dat_i = 2005.
    *Create Date From use in WHERE-Clause
    CONCATENATE '01.01.' l_dat_c_4 INTO l_dat_c_12.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
         EXPORTING
              date_external            = l_dat_c_12
         IMPORTING
              date_internal            = l_dats_from
         EXCEPTIONS
              date_external_is_invalid = 1
              OTHERS                   = 2.
    IF sy-subrc <> 0.
    ENDIF.
    *Create Date To use in WHERE-Clause
    CONCATENATE '31.12.' l_dat_c_4 INTO l_dat_c_12.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
         EXPORTING
              date_external            = l_dat_c_12
         IMPORTING
              date_internal            = l_dats_to
         EXCEPTIONS
              date_external_is_invalid = 1
              OTHERS                   = 2.
    IF sy-subrc <> 0.
    ENDIF.
    * Select records in range
    SELECT *
           FROM [DBTAB]
           INTO TABLE [ITAB]
           WHERE [DATE] BETWEEN l_dats_from
                        AND     l_dats_to.
    Regards
    REA

Maybe you are looking for

  • Accout Determination in Mat doc posting

    Hi, How does the account is determined, during material doc posting.We have two places where the GL account is maintained. 1. In the account assignment tab of PO 2. OBYC settings. Please let me know how the relevant account is selected.

  • Macbook to Asus monitor resolution problem

    I have a '08 Macbook connected to an Asus monitor via DVI. I've been working at 1280 x 800 with a "usable" resolution of 1280 x 720 (listed in Mac Color LCD dialogue box). In the Asus VH238 dialogue box, many higher resolutions are available (max 192

  • ITunes upgrade-- can't upload songs

    I just installed the "new and improved" iTunes 11.0. Now I can't upload new songs from CDs into my music library. Can anyone help me? Thanks!

  • More RAM in Macbook Aluminium??

    Hi, I have a macbook aluminium 2.4Ghz / 4GB DDR3 / 250GB. model MB467BZA. I have a doubt, this mac supports only 4GB Total? If the apple create an BIOS update to supports 8GB RAM>!?? Is this possible?? Thnaks!!!

  • Exchange 2010 Resource '(Mdb)MailboxDatabase001' is unhealthy and shouldn't be accessed.

    Hi Everyone We are getting the below error on all 3 of our mailbox databases when the msexchange assistant runs, we do have retention policies in place but everything in EMC says that all databases are healthy but this event says otherwise. Service M