XPath - is a date null - date

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.

Related

Updating JSONB object using another table

I am trying to update a JSONB field in one table with data from another table. For example,
update ms
set data = data || '{"COMMERCIAL": 3.4, "PCT" : medi_percent}'
from mix
where mix.id = mss.data_id
and data_id = 6000
and set_id = 20
This is giving me the following error -
Invalid input syntax for type json
DETAIL: Token "medi_percent" is invalid.
When I change medi_percent to a number, I don't get this error.
{"COMMERCIAL": 3.4, "PCT" : medi_percent} is not a valid JSON text. Notice there is no string interpolation happening here. You might be looking for
json_build_object('COMMERCIAL', 3.4, 'PCT', medi_percent)
instead where medi_percent is now an expression (that will presumably refer to your mix column).

Xquery to compare the date values in an array and get the max date value

In my xquery i have the condition to check if (SP_TYPE_CD!="") and (max of the EndDate) in an array and return the EndDate that meets this condition
Request:
`<CMS xmlns="*******************">
<CMSService>
<CMSDetails AccountID="123456" CR="1000">
<SA_INFO_LIST>
<SA_INFO_LISTRow SA_ID="3484598047" ServiceAgreementType="OOVRPAY" ServicePointType="" SP_TYPE_CD="" Status="60" StartDate="2018-09-27" EndDate="2018-09-27"/>
<SA_INFO_LISTRow SA_ID="3486640145" ServiceAgreementType="OOVRPAY" ServicePointType="" SP_TYPE_CD="" Status="60" StartDate="2018-04-26" EndDate="2018-04-26"/>
<SA_INFO_LISTRow SA_ID="3487463777" ServiceAgreementType="ERES" ServicePointType="3135182884" SP_TYPE_CD="RESE" Status="70" StartDate="2018-04-06" EndDate=""/>
<SA_INFO_LISTRow SA_ID="3482685560" ServiceAgreementType="OOVRPAY" ServicePointType="" SP_TYPE_CD="" Status="60"
</SA_INFO_LIST>
</CMSServiceDetails>
</CMSService>
</CMS>
My Xquery:
for $SA_INFO_LISTRow in $StartServiceAllowedResponse/ns2:CMSService/ns2:CMSServiceDetails/ns2:SA_INFO_LIST/ns2:SA_INFO_LISTRow
return
if (($SA_INFO_LISTRow/#SP_TYPE_CD)and fn:max($SA_INFO_LISTRow/#EndDate))
then <ns1:date>{(fn:data($SA_INFO_LISTRow/#EndDate)}</ns1:date>
else ()
I am receiving error message when i run the xquery in jdeveloper
FORG0001: "2018-09-27": invalid value for cast/constructor: {http://www.w3.org/2001/XMLSchema}double: error: double: Invalid double value: 2018-09-27
Unless your query is schema-aware, the #endDate attribute (after atomization) will be xs:untypedAtomic, and the max() function attempts to convert xs:untypedAtomic values to dates. You need to tell the query processor to treat the values as dates, which you can do either by making your query schema-aware, or (more simply) by an explicit cast:
fn:max($SA_INFO_LISTRow/#EndDate/xs:date(.))
However, there are other problems with your query. This condition:
if (($SA_INFO_LISTRow/#SP_TYPE_CD) and fn:max($SA_INFO_LISTRow/#EndDate))
(when corrected) is simply asking whether a maximum date exists, and if there are any dates at all, then there will be a maximum, so this is fairly meaningless.
Also, you say you are looking for entries where #SP_TYPE_CD is not equal to "", but your code is looking for all entries where this attribute exists, regardless of its value.
I'm guessing that you actually want the maximum end date of all entries where #SP_TYPE_CD is not equal to "", and that would be (replacing your entire query)
<ns1:date>
{max(//SA_INFO_LISTRow[#SP_TYPE_CD != '']/#EndDate/xs:date(.))}
</ns1:date>

how to change the date format in talend

I have two scenario's,which I couldn't able to solve.
PLZ help me.
Scenario 1:
I've two files Source_1_table(Excel file),Source_2_table(Excel File).
Attached screenshot
I want to compare the source_1 date to source_2 date.
If the source_1 date is matching with source_2 date then the status should be as "Y" if not match then the status should be "N".
Here I am trying with this code row1.date.equals(row2.date)?"Y":"N"
Note:both columns are string data type.
Scenario_2:
Here source_1 SAL column have a null value.and source SAL column have a VALUE.
While I am trying to compare the source_1 sal value with source_2 sal value getting null pointerException.
I am trying with this code relation.Is(source_2.sal)?" ":source_2.sal.equals(source_1.sal)?"Y":"N"
I want to replace a value with empty space or "empty" in null value.
Please look at this snapshot.
Scenario 1: “ row1.Date.equals(row2.Date)?"Y":"N"” is working if both Source 1 & Source 2 contain dates as string.
Scenario 2: To avoid the Null Pointer Exception, check for null values before comparing Source 1 and source data. Please try the expression below:
(row2.SAL == null || row2.SAL == ("")) ? "" : row1.SAL == row2.SAL ? "Y" :"N"

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

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])

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.