How do I query Sitecore items by first version created date? - xpath

It's quite easy to write an XPath or Sitecore Query/Fast query to get all items within a date range:
E.g.
/sitecore/content/*[#__created>='20130301T000000' and #__created<'20130427T000000']
However, this kind of query only looks at the latest version of an item, so it seems impossible to find the actual item's created date (not the version's created date).
I could write a bit of C# code to do the querying but that would involve first retrieving version 1 of every single item in my database before I could then do my filter on created date. This would be mind-bogglingly slow.
Is it possible to do with XPath/Query notation/Fast? If not, is there a way I can do it that will be quick?

I thought of something that might work:
Create a new field which all your items will get. Then in this field, on the creation of an item (not version), you enter the datetime in there.
When versions get deleted, that's fine, because all versions will have that field, with the exact same value.
The only thing is, you'll have to run a script once to loop through your existing items to populate the field with the correct value for each item.
You can then use your XPath query same as now.

Related

How to sort by a derived value that includes a moving date in ElasticSearch?

I have a requirement to sort the results returned by ElasticSearch by a special value i define, let's call it 'X'.
Now - the problem is, 'X' is a value derived based on:
field A in the document (which is a 'term')
field B (which is a 'date')
the current date (UTC)
So, the problem is obviously 3. The date always changes, therefore i'm not sure how to include this in the sort, since it's not part of the document.
From my initial reading it appears i can use a 'script' here, but i'm worried about the performance, since i could be searching + sorting over 1000's of documents.
The only other idea that came to mind is to calculate the value nightly, and store that in each document. But that has a few drawbacks:
i need to have something running in the background to update this value
could be a lot of documents to update (60%+ every night).
i lose precision for the value depending on how long between script runs. (if i run nightly, value is 23 hours 'stale')
Any advice?
Thanks
This can be done by having an ES script run nightly calculating value, and store that in each document

How to get value from a specific row and column in MS ACCESS database?

First, I don't have unique value to directly point out a value I want to retrieve, so there for, I cannot use the WHERE Statement. The reason for that, because I have a database where I constantly updated or deleted, so if I use WHERE statement I have to edit the code again.
Then do apply a unique value - add a field of data type AutoNumber or you will never get out of this mess.

Best practice for single-valued result in SSRS 2012

I'm new to Reporting Services and using SQL Server Data Tools (Visual Studio 2012). I want to add an item that will display a single value - in this case, the result of a stored procedure call. The value would probably be displayed in the report header.
I've looked at the Tablix data parts that can be added to the report: table, list, and matrix. Not sure which of them, if any, would be appropriate. I could add a parameter item, but it seems that these function as user input choices.
I also looked at a read-only text box, but don't see how to populate it with a query result.
What is the accepted method of adding a single-value result to a report?
If this is to be displayed in the page header, your only option is a textbox; you can't add tablix type parts to page headers/footers.
The textbox expression would be something like:
=First(Fields!MyValue.Value, "DataSet1")
By using an aggregate expression like this you can make sure only one value is returned (even though you might always have only one) and you can also specify the aggregate's Scope; in this case the DataSet you want to query.
If this was going in the report body I would still recommend the same approach, though I wouldn't go so far as to call it best practise, any would work so it's really personal taste.
However, if you had multiple fields returned by the SP but still only one row, in that case I would recommend a table style tablix with one header-level row; easiest to maintain and layout.

Linq Lambda sort on DateField

Today something strange happened when I was sorting a list using Linq + lambda.
I have a list with articles that should be OrderedByDescending on a Field c => c.Statistics.Created. This field comes back as a DateTime. I do the following:
newsItems = newsItems.OrderByDescending(c => c.Statistics.Created).ToArray<Item>();
I understand that this list will be ordered in a descending direction and that the time of this date is also being watched as this is just a DateTime object. Now the weird part. I adjust the code to look the following:
newsItems = newsItems.OrderByDescending(c => c.Statistics.Created.Date).ToArray<Item>();
Now when I look at the list, the items are still ordered the way they should be. I can't understand why the list is still ordered the right way, when I tell Linq to only look at the date. Somehow Linq decides to look at the time aswell. When I attach my application to the w3p process and watch what happens I see that the Time is actually empty on the Date object, like I expect.
Can someone explain me how this list actually is getting sorted on time when I tell linq to only look at the date?
Already solved!
I have already found what made this strange behavior occur. It was that the list (gotten out of a CMS) was already ordered some way. When I then sorted on the date (with no time) the order was apperently correct an Linq did no do anything else with this date.

iReport + XPath - Sum String Column

I'm building a report where I have a subreport. This subreport brings some data through XPath, this means it's everything strings from a XML. One of the columns of this subreport has some values, where I need do sum them and show in the end of the table.
I don't know how to put this to work. I've tried to create a variable with sum parameter, but it does not work.
Did anybody need this before?
Scenario:
I load a lot of values from a XPath query, e.g:
/something/something1/something2
This query returns some fields according to my needs. With them I build a table (in a subreport). The problem is: the last column (4), values are strings from XML.
iReport version: 3.0.0
Really thanks!
Solution:
What I needed? According to the original post, a column with strings read from a XML through XPath and a footer with the sum.
Result from column SUM
What to do? Create a variable where you'll keep your sum. After created, edit it. e.g:enter image description here
Fill variable expression with the format you need. Here I used
new BigDecimal($F{theFieldToSum});
Click ok. Now the variable is created, you must create a new TextField where you'll show your sum. Create it and edit it. Here I used the following format:
new java.text.DecimalFormat("#,##0.00").format($V{theVariableYouCreatedBefore})
Click "Apply" and that's all. Compile your report and now you'll have the expected result. For sure, you can do some adapt, but in general this is the process.

Resources