<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Trying to replicate SQL datepart coding in Qlikview in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300421#M1198717</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, can you upload an example qvw and dummy data?&lt;/P&gt;&lt;P&gt;rgds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Jan 2011 18:07:27 GMT</pubDate>
    <dc:creator>hector</dc:creator>
    <dc:date>2011-01-17T18:07:27Z</dc:date>
    <item>
      <title>Trying to replicate SQL datepart coding in Qlikview</title>
      <link>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300416#M1198710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am attempting to replicate some SQL datepart coding in Qlikview in order to compare two dates from 2 different tables (discharge and carepisodes) from a ODBC database: . The SQL is as follows&lt;/P&gt;&lt;P&gt;datepart(year, discharge.disdatetime) = datepart(year, careepisodes.dateto),&lt;BR /&gt;datepart(month, discharge.disdatetime) = datepart(month, careepisodes.dateto),&lt;BR /&gt;datepart(day, discharge.disdatetime) = datepart(day, careepisodes.dateto);&lt;/P&gt;&lt;P&gt;Is there a datepart equivalent in Qlikview?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Matt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 13:24:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300416#M1198710</guid>
      <dc:creator />
      <dc:date>2011-01-14T13:24:40Z</dc:date>
    </item>
    <item>
      <title>Trying to replicate SQL datepart coding in Qlikview</title>
      <link>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300417#M1198712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, you can read this SQL directly in QlikView, like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;CONNECT ..&lt;BR /&gt;&lt;BR /&gt;SQL Select&lt;BR /&gt;.....&lt;BR /&gt;.....&lt;BR /&gt;from.....&lt;BR /&gt;where&lt;BR /&gt;datepart(year, discharge.disdatetime) = datepart(year, careepisodes.dateto),&lt;BR /&gt;datepart(month, discharge.disdatetime) = datepart(month, careepisodes.dateto),&lt;BR /&gt;datepart(day, discharge.disdatetime) = datepart(day, careepisodes.dateto);&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;And answering the other question, yes in qlikview there are year(), month() and day()&lt;/P&gt;&lt;P&gt;Rgds&lt;/P&gt;&lt;P&gt;PS. by the way, if the year, the month and the day is the same, can you replace that section with&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;discharge.disdatetime = careepisodes.dateto&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;or do you have the time (decimals) in this field also?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 13:32:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300417#M1198712</guid>
      <dc:creator>hector</dc:creator>
      <dc:date>2011-01-14T13:32:31Z</dc:date>
    </item>
    <item>
      <title>Trying to replicate SQL datepart coding in Qlikview</title>
      <link>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300418#M1198714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Hector.&lt;/P&gt;&lt;P&gt;The time is in the disdatetime field (i.e. 14/01/2011 13.00:59) but not in the dateto field (14/01/2011) so this is why I am attempting to match the date/month/year only.&lt;/P&gt;&lt;P&gt;Unfortunately I am unable to add the datepart coding into my Edit Script - it keeps coming back with error.&lt;/P&gt;&lt;P&gt;I already have the SQL select command for the careepisodes table and now I am trying to drag in the discharge table:&lt;/P&gt;&lt;P&gt;SQL SELECT patientid as personno,disdatetime, distype&lt;BR /&gt;FROM xxx.dbo.discharge&lt;/P&gt;&lt;P&gt;where datepart(year, discharge.disdatetime) = datepart(year, careepisodes.dateto),datepart(month, discharge.disdatetime) = datepart(month, careepisodes.dateto),datepart(day, discharge.disdatetime) = datepart(day, careepisodes.dateto);&lt;/P&gt;&lt;P&gt;I am stil getting to grips with Qlikview so appreciate this is probably the way I am doing it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Matt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 14:09:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300418#M1198714</guid>
      <dc:creator />
      <dc:date>2011-01-14T14:09:21Z</dc:date>
    </item>
    <item>
      <title>Trying to replicate SQL datepart coding in Qlikview</title>
      <link>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300419#M1198715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again&lt;/P&gt;&lt;P&gt;Please post the script here&lt;/P&gt;&lt;P&gt;By the way, i've just copied and pasted your code, but instead of "," in the where, replace it with and "AND"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;where&lt;BR /&gt;datepart(year, discharge.disdatetime) = datepart(year, careepisodes.dateto) AND&lt;BR /&gt;datepart(month, discharge.disdatetime) = datepart(month, careepisodes.dateto) AND&lt;BR /&gt;datepart(day, discharge.disdatetime) = datepart(day, careepisodes.dateto);&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;maybe another approach it's just floor the date field (because the decimal part is the time fraction), so if you have&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;where floor(disdatetim) = datet&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;Rgds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jan 2011 18:48:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300419#M1198715</guid>
      <dc:creator>hector</dc:creator>
      <dc:date>2011-01-14T18:48:04Z</dc:date>
    </item>
    <item>
      <title>Trying to replicate SQL datepart coding in Qlikview</title>
      <link>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300420#M1198716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry Hector, it seems Qlikview does not recognise the datepart format in my Edit Script command.&lt;/P&gt;&lt;P&gt;In my Expression box where I wish to display the number of results: I have the following:&lt;/P&gt;&lt;P&gt;IF(discharged = 1,caretype = 'N', COUNT({&amp;lt; disdatetime = {'&amp;gt;=$(=Date(vStartdate))&amp;lt;=$(=Date(vEnddate))'} &amp;gt;}surname))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there an alternative date function where I can match day/month/year in here?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Jan 2011 11:56:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300420#M1198716</guid>
      <dc:creator />
      <dc:date>2011-01-17T11:56:25Z</dc:date>
    </item>
    <item>
      <title>Trying to replicate SQL datepart coding in Qlikview</title>
      <link>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300421#M1198717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, can you upload an example qvw and dummy data?&lt;/P&gt;&lt;P&gt;rgds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Jan 2011 18:07:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300421#M1198717</guid>
      <dc:creator>hector</dc:creator>
      <dc:date>2011-01-17T18:07:27Z</dc:date>
    </item>
    <item>
      <title>Trying to replicate SQL datepart coding in Qlikview</title>
      <link>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300422#M1198718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try using NUM() function&lt;/P&gt;&lt;P&gt;Ex: Num(disdatetime ), Num(Date(vStartdate))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Jan 2011 20:20:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300422#M1198718</guid>
      <dc:creator />
      <dc:date>2011-01-17T20:20:07Z</dc:date>
    </item>
    <item>
      <title>Trying to replicate SQL datepart coding in Qlikview</title>
      <link>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300423#M1198719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Hector,&lt;/P&gt;&lt;P&gt;Is there a reason that you need the DATEPART function? If not, you could just simplify the script to&lt;/P&gt;&lt;P&gt;FLOOR(CAST(discharge.disdatetime AS FLOAT)) = FLOOR(CAST(careepisodes.dateto AS FLOAT))&lt;/P&gt;&lt;P&gt;This will ignore the time, but compare everything else.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Aline&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Jan 2011 21:03:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300423#M1198719</guid>
      <dc:creator />
      <dc:date>2011-01-17T21:03:40Z</dc:date>
    </item>
    <item>
      <title>Trying to replicate SQL datepart coding in Qlikview</title>
      <link>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300424#M1198720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks all&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Hector&lt;/STRONG&gt; - Thanks but not sure how to upload example qvw with dummy data?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;qlikviewgoer&lt;/STRONG&gt; and &lt;STRONG&gt;Aline.Koch&lt;/STRONG&gt; -&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks but should your coding be in the Edit Script function or within the Expressions of the Chart Properties?&lt;/P&gt;&lt;P&gt;I tried both and neither worked. When in the Edit Script function, it caused an error and did not recognise the CAST command nor the Num function.&lt;/P&gt;&lt;P&gt;The relevant tables from an ODBC database I am working with is &lt;STRONG&gt;careepisodes&lt;/STRONG&gt; and &lt;STRONG&gt;discharges&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;From the &lt;STRONG&gt;careepisodes&lt;/STRONG&gt; table, I am using&lt;/P&gt;&lt;P&gt;SQL SELECT patientid as personno, projectno, caretype, datefrom as residentdatefrom, dateto as residentdateto&lt;BR /&gt;FROM XXX.dbo.careepisodes where careepisodes.current_ = 1 and careepisodes.projectno not in (....);&lt;/P&gt;&lt;P&gt;From &lt;STRONG&gt;discharges&lt;/STRONG&gt; tables, I am using&lt;/P&gt;&lt;P&gt;SQL SELECT patientid as personno,distype,disdatetime&lt;BR /&gt;FROM XXX.dbo.discharge;&lt;/P&gt;&lt;P&gt;Within the Expression in my Chart box&amp;lt;&lt;/P&gt;&lt;P&gt;IF(discharged = 1,caretype = 'N', COUNT({&amp;lt; disdatetime = {'&amp;gt;=$(=Date(vStartdate))&amp;lt;=$(=Date(vEnddate))'} &amp;gt;}surname))&lt;/P&gt;&lt;P&gt;( I am picking up the Surname field from another table which is working fine)&lt;/P&gt;&lt;P&gt;The above Expression in my chart box is bringing back approx 143 records when the true figure should be approx 93 from the equivalent SQL command. The SQL command uses the datepart command to match the date against disdatetime and dateto (now known as residentdateto in Qlikview) which is where, I think, the problem is as I seem to be unable to replicate this date match command in Qlikview&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jan 2011 17:10:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300424#M1198720</guid>
      <dc:creator />
      <dc:date>2011-01-19T17:10:08Z</dc:date>
    </item>
    <item>
      <title>Trying to replicate SQL datepart coding in Qlikview</title>
      <link>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300425#M1198721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The formula with FLOOR &amp;amp; CAST is T-SQL for SQL Server and is done in the Edit Script Window.&lt;/P&gt;&lt;P&gt;ODBC is a common connection type that can be used with almost any type of modern database.&lt;/P&gt;&lt;P&gt;Your formula above with the Set Analysis should work. In the 93, are you counting both the start date and end dates as well?&lt;/P&gt;&lt;P&gt;If you can create some dummy data in Excel or a table, whichever is easier for you, bring it into a qvw, zip up the data &amp;amp; the qvw, then attach it by clicking the Options tab at the top and clicking on Add under File Attachment, it might be easier to see the issue.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Aline&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jan 2011 19:22:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Trying-to-replicate-SQL-datepart-coding-in-Qlikview/m-p/300425#M1198721</guid>
      <dc:creator />
      <dc:date>2011-01-19T19:22:33Z</dc:date>
    </item>
  </channel>
</rss>

