0

How would I write this SQL as CAML?

CurrentDate = Now()
StartDate = '1-1-2018 12:00 AM'
EndDate = '1-1-2018 11:59 PM'

SELECT * FROM Calendar as c
WHERE (c.EventDate <= CurrentDate AND c.EndDate >= CurrentDate)
    OR (c.EventDate <= StartDate AND c.EndDate <= EndDate)

This link looked good but didn't work for what I am trying to do.

This is the CAML I have but it doesn't work, I get an error undefined:

<View>
  <Query>
    <Where>
      <Or>
        <Leq><FieldRef Name='EventDate' /><Value StorageTZ='TRUE' IncludeTimeValue="FALSE" Type="DateTime">2018-07-01T00:00:00-0400</Value></Geq>
        <Geq><FieldRef Name='EndDate' /><Value StorageTZ='TRUE' IncludeTimeValue="FALSE" Type="DateTime">2018-07-01T00:00:00-0400</Value></Leq>
          <Or>
              <Leq><FieldRef Name='EventDate' /><Value StorageTZ='TRUE' IncludeTimeValue="FALSE" Type="DateTime">2018-07-01T00:00:00-0400</Value></Leq>
              <Geq><FieldRef Name='EndDate' /><Value StorageTZ='TRUE' IncludeTimeValue="FALSE" Type="DateTime">2018-07-01T23:59:59-0400</Value></Geq>
          </Or>
      </Or>
    </Where>
   </Query>
</View>
Heinrich
  • 1,711
  • 5
  • 28
  • 61

1 Answers1

1

Use the CAML Query below.

<Query>
<Where>
        <Or>
            <And>
                <Leq>
                    <FieldRef Name="EventDate"/>
                    <Value IncludeTimeValue='TRUE' Type='DateTime'>2018-07-01T00:00:00Z</Value>
                </Leq>
                <Geq>
                    <FieldRef Name="EndDate"/>
                    <Value IncludeTimeValue='TRUE' Type='DateTime'>2018-07-01T00:00:00Z</Value>
                </Geq>
            </And>
            <And>
                <Leq>
                    <FieldRef Name="EventDate"/>
                    <Value IncludeTimeValue='TRUE' Type='DateTime'>2018-07-01T00:00:00Z</Value>
                </Leq>
                <Leq>
                    <FieldRef Name="EndDate"/>
                    <Value IncludeTimeValue='TRUE' Type='DateTime'>2018-07-01T23:59:59Z</Value>
                </Leq>
            </And>          
        </Or>   
</Where>
</Query>

Here is a SharePoint CAML query designer tool for your reference. https://github.com/konradsikorski/smartCAML

LZ_MSFT
  • 4,079
  • 1
  • 8
  • 9