In jasper report with oracle database where "
(c_order.dateordered >= $P{DateOrdered1} OR $P{DateOrdered1} = '1900/01/01')
AND (c_order.dateordered <= $P{DateOrdered2} OR $P{DateOrdered2} = '1900/01/01') "
is not working by throwing the Literals does not match error.
Try this instead:
(c_order.dateordered >= $P{DateOrdered1} OR $P{DateOrdered1} = to_date('1900/01/01','YYYY/MM/DD'))
AND (c_order.dateordered <= $P{DateOrdered2} OR $P{DateOrdered2} = to_date('1900/01/01','YYYY/MM/DD'))
Related
i trying to build a #Query in one of my repositories which gets a optional Boolean param named "hasComment" in my example. If the Boolean is given/exists i want to make a length check on annother character varying column ("comment") in my where clause.
Currently im having the following code which i didn't expect to work (and isn't of course) but it should show the way i was imagine how it could work.
#Query("SELECT t "
+ "FROM Test t "
+ "WHERE "
+ "(:from IS NULL OR t.startTs >= :from) "
+ "AND (:to IS NULL OR t.endTs <= :to) "
+ "AND ((:hasComment) IS NULL OR ("
+ "(CASE WHEN :hasComment = true THEN length(t.comment) > 0)"
+ "OR (CASE WHEN :hasComment = false THEN length(t.comment) = 0 OR t.comment IS NULL)"
+ ")"
Page<Test> find(#Param("from") Instant from, #Param("to") Instant to,
#Param("hasComment") Boolean hasComment, Pageable pageable);
Can anybody help me out? I just can't really find informations yet how to build this query and even if this is possible at all with a #Query...
I don't think it is possible to use a CASE inside a WHERE condition.
Regarding your query there is a workaround
"AND (:to IS NULL OR t.endTs <= :to) "
+ "AND ((:hasCategory) IS NULL OR ("
+ "(CASE WHEN :hasCategory = true THEN length(t.comment) > 0)"
+ "OR (CASE WHEN :hasCategory = false THEN length(t.comment) = 0 OR t.comment IS NULL)"
+ ")"
to
AND ((:hasCategory) IS NULL OR (
(:hasCategory=true AND length(t.comment)>0) OR
(:hasCategory = false AND length(t.comment) = 0) OR
(:hasCategory = false AND t.comment IS NULL))
)
I have a datatable and want to select some records with LinQ in this format:
var result2 = from row in dt.AsEnumerable()
where row.Field<string>("Media").Equals(MediaTp, StringComparison.CurrentCultureIgnoreCase)
&& (String.Compare(row.Field<string>("StrDate"), dtStart.Year.ToString() +
(dtStart.Month < 10 ? '0' + dtStart.Month.ToString() : dtStart.Month.ToString()) +
(dtStart.Day < 10 ? '0' + dtStart.Day.ToString() : dtStart.Day.ToString())) >= 0
&& String.Compare(row.Field<string>("StrDate"), dtEnd.Year.ToString() +
(dtEnd.Month < 10 ? '0' + dtEnd.Month.ToString() : dtEnd.Month.ToString()) +
(dtEnd.Day < 10 ? '0' + dtEnd.Day.ToString() : dtEnd.Day.ToString())) <= 0)
group row by new { Year = row.Field<int>("Year"), Month = row.Field<int>("Month"), Day = row.Field<int>("Day") } into grp
orderby grp.Key.Year, grp.Key.Month, grp.Key.Day
select new
{
CurrentDate = grp.Key.Year + "/" + grp.Key.Month + "/" + grp.Key.Day,
DayOffset = (new DateTime(grp.Key.Year, grp.Key.Month, grp.Key.Day)).Subtract(dtStart).Days,
Count = grp.Sum(r => r.Field<int>("Count"))
};
and in this code, I try to iterate it with the following code:
foreach (var row in result2)
{
//... row.DayOffset.ToString() + ....
}
this issue occurred :
Object reference not set to an instance of an object.
I think it happens when there's no record with above criteria.
I tried to change it to enumerator like this , and use MoveNext() to check the data is on that or not:
result2.GetEnumerator();
if (enumerator2.MoveNext()) {//--}
but still the same error.
whats the problem?
I guess in one or more rows Media is null.
You then call Equals on null, which results in a NullReferenceException.
You could add a null check:
var result2 = from row in dt.AsEnumerable()
where row.Field<string>("Media") != null
&& row.Field<string>("Media").Equals(MediaTp, StringComparison.CurrentCultureIgnoreCase)
...
or use a surrogate value like:
var result2 = from row in dt.AsEnumerable()
let media = row.Field<string>("Media") ?? String.Empty
where media.Equals(MediaTp, StringComparison.CurrentCultureIgnoreCase)
...
(note that the last approach is slightly different)
So I have 13 binary values, which I call b_1... b_13, and based off these values I'd like to either set something I call indic_j to a previously defined string called inf_j, or nothing at all. Is it possible to do this without using 13 "If..." statements? What I have tried is below:
inf_1 = "aaaaa"
inf_2 = "bbbbb"
... and so on defining 13 infs, where aaaaa, bbbbb etc are names of columns in a table that I want to select.
FOR j = 1 to 13
IF b_j = 1 THEN "indic_"+j = inf_j + ",";
ELSE "indic_"+j = ""
ENDIF
ENDFOR
Also, before this I haven't introduced anything called indic_1, indic_2, etc. Is this needed?
My end goal is to transfer selected columns over to Excel. I've no problems doing this with predetermined columns, but I'm not sure how to allow for selected columns only.
I've tried using 13 IF statements, but I'm getting operator/operand type mismatch errors. My code currently is
IIF(b_1 = 1, indic_1 = inf_1 + ",",indic_1 = "")
IIF(b_2 = 1, indic_1 = inf_2 + ",",indic_1 = "")
IIF(b_3 = 1, indic_1 = inf_3 + ",",indic_1 = "")
and so on for 13 times, and then
SELECTIONRANG = indic_1 + indic_2 + indic_3 + indic_4 + indic_5 + indic_6 +indic_7 + indic_8 + indic_9 + indic_10 + indic_11 + indic_12 + indic_13
SELECTIONRANGE = LEFT(SELECTIONRANG,LEN(Selectionrang)-1)
You could create te variable name as a string and use it with &
As:
ind = 13
Var = "inf_" + ind
&Var ** inf_13
I= 0.299*C1(:,:,1)+0.587*C1(:,:,2)+0.114*C1(:,:,3);
NumberOfGrayLevels=32;
I' =C ln (I+1);
new=uint8(mat2gray(I')*(NumberOfGrayLevels-1));
[m,n]= size(new);
rgb = zeros(m,n,3);
rgb(:,:,1) = new;
rgb(:,:,2) = rgb(:,:,1);
rgb(:,:,3) = rgb(:,:,1);
new = rgb/255;
imshow(new,[]);
no6=figure;
image(new);
this is the code for image generation. error is at I' = . it is showing that + is error.
I assume this is matlab. You're missing operators in the line with an error:
change the third line to:
I=(C*ln(I+1))';
I'm trying to construct a Linq statement to be used from a client with the Sharepoint (2010) object model.
This is the problematic piece of code:
var result = news.Where(n => (bool)n["Online"]
&& ((DateTime)n["StartDate"] <= DateTime.Now && (DateTime)n["StopDate"] >= DateTime.Now));
if (currentUser.IsAgUser())
result = result.Where(n => (string)n["Role"] != "AG-ADMIN");
var filteredNews = sharepointContext.LoadQuery(result);
When the if parte is executed and so another Where is added to result, I get the followin error when LoadQuerying it.
The query expression 'value(Microsoft.SharePoint.Client.ListItemCollection).Where(n => (Convert(n.get_Item("Online")) AndAlso ((Convert(n.get_Item("StartDate")) <= DateTime.Now) AndAlso (Convert(n.get_Item("StopDate")) >= DateTime.Now)))).Where(n => (Convert(n.get_Item("Role")) != "AG-ADMIN"))' is not supported.
Where is the error coming from? Thanks
It seems like SharePoint doesn't support several wheres.
Cheap solution:
var result = currentUser.IsAgUser()
? news.Where(n => (bool)n["Online"]
&& ((DateTime)n["StartDate"] <= DateTime.Now && (DateTime)n["StopDate"] >= DateTime.Now) && (string)n["Role"] != "AG-ADMIN")
: news.Where(n => (bool)n["Online"]
&& ((DateTime)n["StartDate"] <= DateTime.Now && (DateTime)n["StopDate"] >= DateTime.Now));
var filteredNews = sharepointContext.LoadQuery(result);