0
query.Query = @"<Where>
<And>
<BeginsWith>
<FieldRef Name='ContentTypeId'/>
<Value Type='Text'>[LONG GUID]</Value>
</BeginsWith>
<And>
<Geq>
<FieldRef Name='PublishingStartDate' />
<Value Type='DateTime'>2011-01-01T15:55:52Z</Value>
</Geq>
<Leq>
<FieldRef Name='PublishingStartDate' />
<Value Type='DateTime'>2011-01-01T15:55:52Z</Value>
</Leq>
</And>
</And>
</Where>
<OrderBy>
<FieldRef Name='PublishingStartDate' Ascending='FALSE' />
</OrderBy>";

The above query is attempting to bring back all items of a certain content type between two dates and order (descending) by the same date field.

EDIT: I should mention that this is an SPSiteDataQuery

  • I've narrowed it down to the OrderBy clause - can anyone see a problem with it? (field definitely exists). –  Jun 20 '12 at 13:42
  • 1
    I see two root elements `Where` and `OrderBy` – L.B Jun 20 '12 at 13:48
  • I didn't think this mattered when assigning it to a Query property (i.e. the query property encloses all of this string in tags so that there's in effect only 1 by the time the query's ran?) I may be wrong, I'm new to this. What do you propose? +1. –  Jun 20 '12 at 13:50
  • 1
    @Daniel Having `Where` and `OrderBy` as "twin" root elements here is fine. – Rawling Jun 20 '12 at 13:55
  • I thought so. Thanks Rawling. Could the problem be that it's trying to order the results but there are none (I can confirm that this query yields 0 results)? I doubt it, but I can't think of anything else. –  Jun 20 '12 at 13:56
  • 1
    I can't see anything wrong with your CAML. All I can suggest is, try it with some records returned (use different dates?), with and without the OrderBy clause, see what happens. – Rawling Jun 20 '12 at 14:04
  • I will try that, but it's not really acceptable that it would raise an exception when there are no results. Thanks a lot. –  Jun 20 '12 at 14:07

2 Answers2

1

I do not see anything wrong in your CAML. One thing I noticed is the value of the PublishingStartDate filter values. Both Geq and Leq are having exactly the same date time value.

<Geq>
<FieldRef Name='PublishingStartDate' />
<Value Type='DateTime'>2011-01-01T15:55:52Z</Value>
</Geq>
<Leq>
<FieldRef Name='PublishingStartDate' />
<Value Type='DateTime'>2011-01-01T15:55:52Z</Value>
</Leq>

Are you sure that both filter should be using the same date time?

Senthil S
  • 75
  • 7
  • +1 for that Senthil, thanks. To be honest it's demo data for now for the sake of this thread but you'd have been spot on if it wasn't. –  Jun 23 '12 at 19:58
0

Maybe it's too late to answer this, but for further reference: the problem is that you can't have new line symbols in the query or view felds. I had the same problem - if you put all of CAML on one row, it will work.