WHERE Statement Help
Hi,
cant get to grips with this problem, need to select from
dbo.booking_form
all records that meet 2 statements. 1st allocated='completed'
and 2nd
account is not 'CASH' , ie all records that don't contain the
word CASH in
the field 'ACCOUNT' Below is the beginning just don't know
the syntax for
NOT, have tried several option but to no avail.
Pricing.Source = "SELECT * FROM dbo.booking_form WHERE
allocated =
'COMPLETED' AND
Thanks in advance.
Simon
Baxter wrote:
> AND WHERE ACCOUNT NOT LIKE CASH
You might also try WHERE ACCOUNT != 'CASH'; at least, I think
that's
another way to do it.
> Dave
> "Simon Gare" <[email protected]> wrote in message
> news:e745k8$8dl$[email protected]..
>> Hi,
>>
>> cant get to grips with this problem, need to select
from dbo.booking_form
>> all records that meet 2 statements. 1st
allocated='completed' and 2nd
>> account is not 'CASH' , ie all records that don't
contain the word CASH in
>> the field 'ACCOUNT' Below is the beginning just
don't know the syntax for
>> NOT, have tried several option but to no avail.
>>
>> Pricing.Source = "SELECT * FROM dbo.booking_form
WHERE allocated =
>> 'COMPLETED' AND
>>
>> Thanks in advance.
>>
>> Simon
>>
>>
>
>
www.geobop.org - Family Websites
www.invisible-republic.org - Adult political websites
www.freedomware.us - The truth about Microsoft
www.jail4bush.org - Tom Muck's favorite!
Similar Messages
-
Applied an update to an app that records blood pressure. Am unable to retrieve previously stored info. When following directions in update, I cannot "add" data to import because message states data are stored elsewhere, and I cannot find where. Help?
You'll have to contact the app developer for help with this.
-
Recently in the Bahamas where I helped a friend with his new iPad. We could not find Bahamas in initial setup so we used United States and could not enter Visa/MC billing address in Bahamas. iTunes rejected, billing info is not what's on file. What to do?
Just to recap, this is a collection of ports I have collected over time for people who needed this information when setting up the HP ePrint app so that they could view their email from within the app. I am certain other applications also need this information. Although lengthy, I could not find a more comprehensive place to retrieve this information. Feel free to post additional information, faulty information, or other related topics below as this is simply a collection of data and it would be practically impossible to test all of them. Thank you!
Don't forgot to say thanks by giving "Kudos" if I helped solve your problem.
When a solution is found please mark the post that solves your issue.
Every problem has a solution! -
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 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.
CFmongerThis 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> -
Left outer join 3 tables with where-statement
Hi folks,
I hope you can understand (and maybe solve) my problem.
Generally I try to left outer join three tables. The third table is used for a WHERE-statement.
The three table structures are the following:
table 1 (user)
user1 | key
table 2 (detail)
key | ID
table 3 (header)
ID | user2
...and I want to achieve the following structure (as example filled with data):
user | key | ID
|-----|----
xy | a | 001
xy | b | #
z | b | #
The clue ist the usage of the third table. I need the table to set user1 and user2 equal (WHERE) but there are two problems:
1) Obviously I can't left outer join two tables with each other. In this case I already used the 'key' of table 1 to join it with the 'key' of table 2. So I can't left outer join the 'ID' of table 2 with the 'ID' of table 3. Error message that I can only left outer join a table once. Any proposals?
2) I have to include a WHERE to equal user1 with user2. But I am not allowed to use the user2 from table 3 because of the left outer join.
I tried this coding:
SELECT auser1 akey b~id INTO TABLE itab FROM ( table1 AS a
LEFT OUTER JOIN table2 AS b ON akey = bkey )
LEFT OUTER JOIN table3 AS c ON bID = cID )
WHERE auser1 = cuser2.
I would really appreciate your help.
Regards
MrclSpdlIF you want to join a DB table with an internal table, you need to use the 'FOR ALL ENTRIES' statement.
select dbfields
into table itab2
from dbtab
for all entries in itab
where dbfield1 = itab-field1.
This will get you a second internal table with all the corresponding data for the first selection. You can then join them with a loop through the first table and a read table on the second table (for 1 - 1 relation) or a nested loop statement on both tables (for 1 - N relation). Make itab a hashed table when using read table with key, use a sorted table if you need to loop without key access.
Regards,
Freek -
Hi,
I need a possibility to enter the where-statement at runtime.
In the "SQL Query Statement" I can enter a query and parameters.
My Problem ist that at runtime my forms-application builds the where-Part of the sql-statement and then sends it to the report.
I know that reports has the &where_clause option.
In &where_clause I can enter the whole where-clause of every statement.
But how can I "tell" reports that it's query should based on this &where_clause???
In other words: can I set the "sql Query Statement" at runtime?
Thank you for your help
bye
FlorianHi Florian,
In the data model, you can create a user parameter "P_WHERE" varchar2(1000), set your query like this:
select col1,...coln
from table
where &P_WHERE;
At the run time, you should pass the Where value from
your form_application and send it to the parameter P_WHERE
of the report.
Hope this helps,
CB -
[PERSISTENCE CLASS] SELECT OPTION in WHERE statement
Hi Gurus,
I would like to know how could I code the WHERE statement with a SELECT OPTION, in Persistence Class ?
Currenlty, I would like to code this kind of request :
DELETE FROM ziTab
WHERE zdate IN so_date.
Do you know, how could I code it ?
Many thx for helps.
Best regards.
Rachid.Sorry Glen,
Unfortunately, I am trying to find the correct syntax to use a SELECT OPTION in a Query Request of Persistence Class:
Something like that:
SELECT-OPTIONS so_date FOR sy-datum .
DATA lo_query_manager TYPE REF TO if_os_query_manager .
DATA lo_query TYPE REF TO if_os_query .
DATA lo_agent TYPE REF TO zca_persistence_zint_rsbankinv.
DATA lo_base TYPE REF TO zcb_persistence_zint_rsbankinv.
DATA lo_rsbankinv TYPE REF TO zcl_persistence_zint_rsbankinv.
DATA lo_table TYPE osreftab .
DATA ls_table TYPE REF TO zcl_persistence_zint_rsbankinv.
DATA ls_tmp TYPE REF TO object .
DATA lv_string TYPE string .
DATA lo_exception TYPE REF TO cx_root .
TRY .
lo_agent = zca_persistence_zint_rsbankinv=>agent.
* Create Query
lo_query_manager = cl_os_system=>get_query_manager( ).
lo_query = lo_query_manager->create_query( i_filter = 'ZEXDAT IN PAR1' ).
lo_table =
lo_agent->if_os_ca_persistency~get_persistent_by_query(
i_query = lo_query
i_par1 = so_date
LOOP AT lo_table INTO ls_tmp.
ls_table ?= ls_tmp .
lv_string = ls_table->zget_all_fields( ).
WRITE lv_string.
ENDLOOP.
CATCH cx_root INTO lo_exception.
lv_string = lo_exception->get_text( ).
WRITE lv_string.
ENDTRY.
But I have an error message :
Syntax error when parsing a query : Excepected symbol 'IN' (row: O, column: 7)
Any idea ? -
Nav attribute in where-statement
Hi Experts,
I have a routine in which I want to select 0MAT_SALES where my navigation attribute ZACCASGRP equals some values. I have written the code below but I get a syntax error when trying to compile it. I do not get any suggestions and I have not been able to figure out the problem.
data: BEGIN OF Z_FUNDGROUP occurs 0,
/BI0/OIMAT_SALES TYPE /BIC/AZBILCOPA00-MAT_SALES,
END OF Z_FUNDGROUP.
SELECT * FROM /BIC/AZBILCOPA00
Into corresponding fields of table Z_FUNDGROUP
where MAT_SALES-ZACCASGRP IN ('a', 'b', 'c').
My problem is the where-statement and I have also tried with the following combinations but non of them works:
/BI0/OIMAT_SALES-ZACCASGRP
/BI0/OIMAT_SALES-0MAT_SALES__ZACCASGRP
MAT_SALES-0MAT_SALES__ZACCASGRP
if I change it to only say: where MAT_SALES IN ('a', 'b', 'c'). I do not get the error (but this is of course useless since I am not restricting on my navigation attrivute).
Can somebody please help me with this.
Thank you in advance,
MikaelHi,
You are probably right regarding the Select-statement above. I therefore reasoned that I should be able to re-structure my problem and use the following select-statements instead:
SELECT MAT_SALES
FROM /BI0/PMAT_SALES
INTO TABLE Z_FUNDGROUP
WHERE
MAT_SALES IN (
SELECT DISTINCT MAT_SALES
FROM /BIC/AZBILCOPA00
AND /BIC/ZACCASGRP IN ('a', 'b', 'c').
but when I do this I still get errors. If I skip the "AND /BIC/ZACCASGRP IN ('a', 'b', 'c')" part it gives me valid results, but I have to be able to use this attribute. When I look at the master data table /BI0/PMAT_SALES in SE16 it shows me that there is a field named /BIC/ZACCASGRP and then I do not understand why I cannot use the above select.
Best regards,
Mikael -
I'm struggling with my WHERE statement below. I've bolded the couple of lines giving me trouble. Basically, I just need data returned when oh.ship_actual_date is null or it has a date equal to the sysdate. Any help would be much appreciated.
select oh.order_number
, oh.SHIP_ACTUAL_DATE
, trunc(oh.order_date) as "Order Date"
, trunc(oh.SHIP_UNTIL_DATE) as "Expected Ship"
, oh.order_status
, masterdata.getpicklisttext(:language_code, oh.order_status, 80) as order_status
, masterdata.GetPickListText('E',Sales.Get_Order_Shipping_Status(oh.order_number),150) AS shipping_status
from order_header oh , order_parts op
where oh.order_sub_type = 'LRS'
and oh.order_number = op.order_number
and oh.order_status not in( 'Q', 'V','C','M')
and nvl(oh.drop_ship_only,'N') = 'N'
*and oh.ship_actual_date = trunc(sysdate)*
*OR oh.ship_actual_date is null*
group by oh.order_number
, oh.order_date
, OH.SHIP_UNTIL_DATE
, oh.ship_actual_date
, oh.order_status
order by OH.SHIP_UNTIL_DATE ascHi,
847497 wrote:
*and oh.ship_actual_date = trunc(sysdate)*
*OR oh.ship_actual_date is null*
Don't mix AND and OR without using parentheses to make your meaning clear.
AND ( oh.ship_actual_date = TRUNC (SYSDATE)
OR oh.ship_actual_date IS NULL
)should do what you want, assuming oh.ship_actual_date is midnight. (And assuming you want what I think you want. When you don't post sample data, results and an explanation, people are just guessing.)
If the hours, minutes and seconds of oh.ship_actual_date are not 00:00:00, then use something like:
AND ( ( oh.ship_actual_date >= TRUNC (SYSDATE)
AND oh.ship_actual_date < TRUNC (SYSDATE) + 1
OR oh.ship_actual_date IS NULL
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Simplify the problem as much as possible. If the only thing that you don't know how to do is the date comparison, post a problem that involves only the date comparison: no joins, very few columns.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002}
Edited by: Frank Kulash on Oct 2, 2012 12:57 PM
You can get the right results using
TRUNC (oh.ship_actual_date) = TRUNC (SYSDATE) but it will be inefficient. Why? Discuss. -
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. -
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!
CFmongerAll 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. -
Using alias in where statement
simple sql:
SELECT EMPLOYEE_ID,
FIRST_NAME,
LAST_NAME,
EMAIL,
PHONE_NUMBER,
HIRE_DATE,
JOB_ID,
SALARY,
COMMISSION_PCT,
MANAGER_ID,
DEPARTMENT_ID
FROM EMPLOYEES
WHERE EMPLOYEE_ID > 1000;
is it somehow possible to use alias in where statement like
SELECT EMPLOYEE_ID "ID",
FIRST_NAME,
LAST_NAME,
EMAIL,
PHONE_NUMBER,
HIRE_DATE,
JOB_ID,
SALARY,
COMMISSION_PCT,
MANAGER_ID,
DEPARTMENT_ID
FROM EMPLOYEES
WHERE "ID" > 1000;Hi,
is it somehow possible to use alias in where statement likeWhy do you need it?
To answer your question "Not directly"
SQL> select empno eno, sal
2 from emp
3 where eno = 7900;
where eno = 7900
ERROR at line 3:
ORA-00904: "ENO": invalid identifierColumn Alias are names given to give meaningful names to columns or the arithmetic operations' column.
Twinkle -
I find it annoying that you can't use aliases in where statements
I find it annoying that you can't use aliases in where
statements
for example:
SELECT TOP 1
CAST(amount
/ ( CASE WHEN ISNULL(rate, 0) <> 0 THEN rate
ELSE 1
END ) AS NUMERIC(10, 2)) AS num
FROM table
WHERE num > 1
ORDER BY num
Are there any workarounds?> I find it annoying that you can't use aliases in where
statements
This isn't really (or... "at all") a CF question. You're
better off asking
this sort of thing on a SQL Server forum.
You could use a derived table, I guess:
select top 1 num
from (
SELECT
CAST(amount
/ ( CASE WHEN ISNULL(rate, 0) <> 0 THEN
rate
ELSE 1
END ) AS NUMERIC(10, 2)) AS num
FROM table
where num > 1
order by num
(that might not preserve the intent of you SQL (sorry: it's
late, I'm
tired), but you get the idea.
Adam -
Group function is not allowed here - where statement
I have a select that is basically:
select a,b,
sum(c),sum(d),
sum(c) - sum(d)
from A
group by a, b
I would like to add:
where sum(c) - sum(d) <> 0
I know that I can't use the sum function in the where statement.
Any ideas how I can get around it?
Thanks.
LeahHi ,
for instance ... using the count aggregate function... which is the same as using sum function.....
SQL> select job , cnt_emp , cnt_sal
2 from
3 (
4 select job, count(empno) cnt_emp, count(sal) cnt_sal
5 from emp
6 group by job
7 )
8 where cnt_emp- cnt_sal=0
9 /
JOB CNT_EMP CNT_SAL
CLERK 5 5
SALESMAN 5 5
PRESIDENT 1 1
MANAGER 3 3
ANALYST 2 2Greetings....
Maybe you are looking for
-
My time line marker keeps freezing. I can fix the problem by turning the program of and then back on. Am I doing anything to cause this freezing to happen randomly?
-
Error when inserting a new record (Ctrl+Down)
Hello, [http://img402.imageshack.us/my.php?image=12846351.jpg] Here the problem is : when i press Ctrl+Down (Insert new record), i enter data into all those fields, but i got an error Cannot Insert Record ("ROGER"."NUME") cannot be null (roger is my
-
Some of my files in pages won't open
Some of my files in pages won't open they say they are downloading and updating but this has been happening for 4weeks? And I can't access the information
-
Several example VIs have tab controls with 'thick' borders. When I drop a tab control from the palette onto a vi, it has thin borders, and I can't work out how to change them. I'm sure its dead simple, but I can't find it! Thanks in advance, Ian
-
Hello, I have a litlle problem while trying to upload feeds and pictures and video form my application to facebook. I success on connecting to facebook, but when I try to upload stuff, that fails, and whithout any error message so I can't debug. I fo