An access query comparing the time part in a date field with values input in a form - date

I have an access query with predicates (conditions) on a date/time column called start_time. The condition is on two form fields defined with "Format" as "short time". The problem is that this query does not give correct results.
SELECT event_cust.*
FROM event_cust
WHERE Format([start_time],"hh:mm")
BETWEEN [Forms]![CustEventRptForm]![FromHour]
AND [Forms]![CustEventRptForm]![ToHour]
Also tried it using Format([start_time], "short time") BETWEEN ... - did not work either.
Do we need anything in addition to above code to get the correct results?
I have tested with literal values as shown below and I get correct results with that.
SELECT event_cust.*
FROM event_cust
WHERE Format([start_time],"hh:mm") BETWEEN '10:00' AND '13:00'

My guess is it's not interpreting the value from the form correctly.
Try adding quotes before and after the values:
SELECT event_cust.*
FROM event_cust
WHERE Format([start_time],"hh:mm") Between "" & [Forms]![CustEventRptForm]![FromHour] & ""
And "" & [Forms]![CustEventRptForm]![ToHour] & ""

Don't use string comparisons for date/times.
SELECT event_cust.*
FROM event_cust
WHERE TimeValue([start_time]) >= CDate([Forms]![CustEventRptForm]![FromHour])
AND TimeValue([start_time]) <= CDate([Forms]![CustEventRptForm]![ToHour])

Related

string query in a function in kdb

func:{[query] value query};
query is part of my function. I have add some like delete xxx, yyyy from (value query) and some manipulation. I am not sure why when I don't use value "query", the function doesn't work. It said it cannot find the table. So I have to use value query in the function and query is a parameter. I need to pass "select from tab" to the function.
My questions is: how do I send if the filter is a string too?
func["select from tab where a="abc""] <<< this does not work
How can I make string inside a string work?
Also, not sure why if I do
func["select from tab where date = max date"] it did not work due to length error
but func["100#select from tab where date = max date"] it works ?
The whole function is
getTable:{[query]loadHDB[];.Q.view date where date < .z.D-30;tab:(delete xxxx,yyyyy,sub,ID,subID,tID,subTID,text,gID from((value query)));remove[];update {";"sv #[s;where (s:";"vs x) like "cId=*";:;enlist""]}each eData from (update {";"sv #[s;where (s:";"vs x) like "AId=*";:;enlist""]}each eData from tab)};
remove:{[]delete tab from `.};
loadHDB:{[]value "\\l /hdb};
You can escape the quotes using backslash http://code.kx.com/wiki/Reference/BackSlash#escape
func["select from tab where a like \"abc\""]
Edit:
If tab is a HDB table then this length error could point to a column length issue (which 100# is avoiding). What does the following return?
q)checkPartition:{[dt] a!{c!{count get x} each ` sv' x,/:c:({x where not x like "*#"} key[x])except `.d}each a:(` sv' d,/:key[d:hsym `$string dt])};
q)check:checkPartition last date
q)(where{1<count distinct value x}each check)#check
I like using -3! and also -1 to print the result. If you know what your query should look like if executed from the console then after you construct your string, use -1 to print the string. It should print the query as how it would be executed by the console.
q)stst:-3!
q)"select max age by user from tab where col1 like ",stst"Hello"
"select max age by user from tab where col1 like \"Hello\""
q)/then to view how it will be executed, use -1
q)-1"select max age by user from tab where col1 like ",stst"Hello";
select max age by user from tab where col1 like "Hello"
q)/looks good

Crystal reports selecting record that contain empty strings or "null"

I have a report that for a field called JobNo there are some records that have "null" as the the cell value and some that have an empty string "". there is another field called AccntNo that im also selecting by in the same selection formula.
This is what i have tried without success in the selection formula for crystal reports.
{accnt.accno} = "7015" and
{accnt.jobno} = "" or {accnt.jobno} isnull
any help is apreciated
Selection formula doesn't work as expected, sometimes.
I suppose that this will work
{accnt.accno} = "7015" and
( isnull({accnt.JobNo}) or {accnt.jobno} = "" )
First of all I put parenthesis on 'or' clause.
But, the strangest thing, is that isnull clause must be evaluated before other comparison clauses.

Insert null value to date field in access using vba

Am trying to insert date from a table to another table using vba in access, But one of the date values from the table is blank. So while inserting the date to new table it shows Invalid use of null exception Run-time error 94.
If writing DAO code to clear a Date field, I found that I had to use "Empty". Null and "" won't work. So for field dtmDelivery (type Date), I had to use the following. strDelivery is just a string with the date in it.
Set rst = dbs.OpenRecordset("tblSomething", dbOpenDynaset)
If (strDelivery = "") Then
rst!dtmDelivery = Empty
Else
rst!dtmDelivery = strDelivery
End If
rst.Update
you can use the NZ() function to define a value that should be used instead of NULL. Internally a date is a float value where the number represents the days between 01.01.1900 and the date that should be stored. The part behind the decimal point represents hours/minutes (.25 for example is 6 AM). So you can use the NZ() funtion to replace NULL bei 0 (what would be interpreted as 01.01.1900).
Another solution would be to configure the target table in a way that it allows NULL values. You can do this easily in the design view of the table.
I think i figure it out , declare the variable to string. Then check whether value from the table is empty, then assign null to it.Other wise assign the value from the table.
for example
Dim newdate As String
Check whether the fetched values is null or not
If IsNull(rst![value]) Then
newdate = "null"
Else
newdate = rst![value]
End If
I encountered this problem and solved it this way.
SQL = "update mytable set mydatefield = '" & txtdate & "'"
On the txtdate on your form, put a date format to ensure date is either a real date or just blank.

XPath - is a date null

Using XPath, how do I figure out if a date or datetime field is null or blank?
I am using the concat method as a stand-in for the XPath if statement
concat(
substring(../preceding-sibling::my:PerDiem[1]/my:perDiemEnd, 1, ../preceding-sibling::my:PerDiem[1]/my:perDiemEnd = "" * string-length(../preceding-sibling::my:PerDiem[1]/my:perDiemEnd)),
substring(/my:ExpenseForm/my:ExpenseHeader/my:departureDateTime, 1, not(../preceding-sibling::my:PerDiem[1]/my:perDiemEnd = "") * string-length(/my:ExpenseForm/my:ExpenseHeader/my:departureDateTime))
)
More info:
In Infopath 2010, a repeating table has two date/time fields called perDiemStart and perDiemEnd. In the repeating table, the next perDiemStart is the previous perDiemEnd. This is easily done if the default value of perDiemStart is ../preceding-sibling::my:PerDiem[1]/my:perDiemEnd
But for the first perDiemStart (since a previous perDiemEnd does not exist, I suppose it would be null/blank). I want that first (blank) value to be a different: value of departureDateTime node
Node locations:
/my:ExpenseForm/my:ExpenseHeader/my:departureDateTime
/my:ExpenseForm/my:PerDiemDetails/my:PerDiems/my:PerDiem/my:perDiemStart
/my:ExpenseForm/my:PerDiemDetails/my:PerDiems/my:PerDiem/my:perDiemEnd
To check if it is filled:
perDiemStart[text()]
To check if it is empty/null:
perDiemStart[not(text())]
Does this help? http://blogs.msdn.com/b/syamp/archive/2011/03/13/fim-2010-xpath-how-to-check-null-value-on-a-datetime-attribute.aspx
Basically they detect null dates by getting the set of dates after an old date (e.g. 1900-01-01) and then using 'not' to see which nodes would be excluded.

String comparisons in JasperReports expressions

A database field named income_source is queried using:
SELECT * FROM table_name WHERE income_source LIKE "salaried%"
This retrieves income_source values with a "salaried" prefix. In iReport, the PrintWhenExpression value for the field is set as:
$F{income_source}.equals("Salaried")? Boolean.TRUE:Boolean.FALSE
Why does the report output differ from the SQL output?
There are a few problems:
The value "salaried%" in the SQL differs from the value of "Salaried" in the expression.
The value "salaried%" uses the % to match all text after the letter d.
There is a bit of redundancy in the PrintWhenExpression.
Try the following expression:
$F{income_source}.startsWith( "salaried" )
Or:
$F{income_source}.trim().toLowerCase().startsWith( "salaried" )
One of those should work. You will also want to ensure Blank when null is checked. Otherwise, the expression becomes:
$F{income_source} == null ? Boolean.FALSE :
$F{income_source}.trim().toLowerCase().startsWith( "salaried" )