SQL query to select records where date field is certain week number











up vote
0
down vote

favorite












I have no own "script syntax" for my application. It is designed for creating simple reports from a Microsoft Access Database using JET. Here is a simple example:



REQUIRES "Min number of away talks:" AS $iMinNumAwayTalks
LOOP FROM "Home Talks" NODATERANGE WHERE "Last Given" ISMOREOREQUAL "$Today" SORTBY "Last Given"
SHORTDATE_FIELD "Last Given"
TAB =5>
TEXT "Week: "
VARIABLE_FIELD "Last Given" "$iWeekNo#CUSTOMDATE[%W]"
TEXT "$iWeekNo"
$iAwayTalkCount = 0
LOOP FROM "Away Talks" NODATERANGE WHERE "Talk Date" ISMOREOREQUAL "$Today" SORTBY "Talk Date"
VARIABLE_FIELD "Talk Date" "$iAwayWeekNo#CUSTOMDATE[%W]"
IF "$iAwayWeekNo" IS "$iWeekNo"
$iAwayTalkCount = $iAwayTalkCount + 1
END_IF
END_LOOP
TAB =10>
TEXT "# Away: "
TEXT "$iAwayTalkCount"
TAB =15>
TEXT "$iMinNumAwayTalks"
TEXT " Exceed? "
IF "$iAwayTalkCount" ISMORE "$iMinNumAwayTalks"
TEXT "Yes"
END_IF
IF "$iAwayTalkCount" ISLESSOREQUAL "$iMinNumAwayTalks"
TEXT "No"
END_IF
EOL
END_LOOP


It is basically looking at two tables to work out how many records have the same Week Number (beginning Monday) for the specified fields.



My question relates to this query I have used:



LOOP FROM "Away Talks" NODATERANGE WHERE "Talk Date" ISMOREOREQUAL "$Today"  SORTBY "Talk Date"


The downside with this query is that is is selecting all records greater than today and then I have to examine each record to see if the "Talk Date" field has the same week number.



Results



Now, my script syntax supports raw SQL loops too. So is it possible using a raw Microsoft Access JET SQL query to:



Select all Away Talks where the Talk Date field is Week X (where Week is week starting Monday)?



I have tried to do a manual test in Access 2016 with the criteria:



SELECT [Away Talks].[Talk Date]
FROM [Away Talks]
WHERE ((DatePart('ww',[Talk Date],'vbMonday')=45));


But I have an error:



Access Error



What am I doing wrong?










share|improve this question


















  • 1




    You will need to filter on both year and week as week 01 and 52/53 may cross calendar boundaries. For example, week 2019-01 spans 2018-12-31 to 2019-01-06. Also, there is no week 00.
    – Gustav
    Nov 7 at 12:23










  • @Gustav Ah, these values are from my MFC program and it returns 0 to 51. So I must add 1 to those results. Thanks. And I thought about the year too.
    – Andrew Truckle
    Nov 7 at 12:59















up vote
0
down vote

favorite












I have no own "script syntax" for my application. It is designed for creating simple reports from a Microsoft Access Database using JET. Here is a simple example:



REQUIRES "Min number of away talks:" AS $iMinNumAwayTalks
LOOP FROM "Home Talks" NODATERANGE WHERE "Last Given" ISMOREOREQUAL "$Today" SORTBY "Last Given"
SHORTDATE_FIELD "Last Given"
TAB =5>
TEXT "Week: "
VARIABLE_FIELD "Last Given" "$iWeekNo#CUSTOMDATE[%W]"
TEXT "$iWeekNo"
$iAwayTalkCount = 0
LOOP FROM "Away Talks" NODATERANGE WHERE "Talk Date" ISMOREOREQUAL "$Today" SORTBY "Talk Date"
VARIABLE_FIELD "Talk Date" "$iAwayWeekNo#CUSTOMDATE[%W]"
IF "$iAwayWeekNo" IS "$iWeekNo"
$iAwayTalkCount = $iAwayTalkCount + 1
END_IF
END_LOOP
TAB =10>
TEXT "# Away: "
TEXT "$iAwayTalkCount"
TAB =15>
TEXT "$iMinNumAwayTalks"
TEXT " Exceed? "
IF "$iAwayTalkCount" ISMORE "$iMinNumAwayTalks"
TEXT "Yes"
END_IF
IF "$iAwayTalkCount" ISLESSOREQUAL "$iMinNumAwayTalks"
TEXT "No"
END_IF
EOL
END_LOOP


It is basically looking at two tables to work out how many records have the same Week Number (beginning Monday) for the specified fields.



My question relates to this query I have used:



LOOP FROM "Away Talks" NODATERANGE WHERE "Talk Date" ISMOREOREQUAL "$Today"  SORTBY "Talk Date"


The downside with this query is that is is selecting all records greater than today and then I have to examine each record to see if the "Talk Date" field has the same week number.



Results



Now, my script syntax supports raw SQL loops too. So is it possible using a raw Microsoft Access JET SQL query to:



Select all Away Talks where the Talk Date field is Week X (where Week is week starting Monday)?



I have tried to do a manual test in Access 2016 with the criteria:



SELECT [Away Talks].[Talk Date]
FROM [Away Talks]
WHERE ((DatePart('ww',[Talk Date],'vbMonday')=45));


But I have an error:



Access Error



What am I doing wrong?










share|improve this question


















  • 1




    You will need to filter on both year and week as week 01 and 52/53 may cross calendar boundaries. For example, week 2019-01 spans 2018-12-31 to 2019-01-06. Also, there is no week 00.
    – Gustav
    Nov 7 at 12:23










  • @Gustav Ah, these values are from my MFC program and it returns 0 to 51. So I must add 1 to those results. Thanks. And I thought about the year too.
    – Andrew Truckle
    Nov 7 at 12:59













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have no own "script syntax" for my application. It is designed for creating simple reports from a Microsoft Access Database using JET. Here is a simple example:



REQUIRES "Min number of away talks:" AS $iMinNumAwayTalks
LOOP FROM "Home Talks" NODATERANGE WHERE "Last Given" ISMOREOREQUAL "$Today" SORTBY "Last Given"
SHORTDATE_FIELD "Last Given"
TAB =5>
TEXT "Week: "
VARIABLE_FIELD "Last Given" "$iWeekNo#CUSTOMDATE[%W]"
TEXT "$iWeekNo"
$iAwayTalkCount = 0
LOOP FROM "Away Talks" NODATERANGE WHERE "Talk Date" ISMOREOREQUAL "$Today" SORTBY "Talk Date"
VARIABLE_FIELD "Talk Date" "$iAwayWeekNo#CUSTOMDATE[%W]"
IF "$iAwayWeekNo" IS "$iWeekNo"
$iAwayTalkCount = $iAwayTalkCount + 1
END_IF
END_LOOP
TAB =10>
TEXT "# Away: "
TEXT "$iAwayTalkCount"
TAB =15>
TEXT "$iMinNumAwayTalks"
TEXT " Exceed? "
IF "$iAwayTalkCount" ISMORE "$iMinNumAwayTalks"
TEXT "Yes"
END_IF
IF "$iAwayTalkCount" ISLESSOREQUAL "$iMinNumAwayTalks"
TEXT "No"
END_IF
EOL
END_LOOP


It is basically looking at two tables to work out how many records have the same Week Number (beginning Monday) for the specified fields.



My question relates to this query I have used:



LOOP FROM "Away Talks" NODATERANGE WHERE "Talk Date" ISMOREOREQUAL "$Today"  SORTBY "Talk Date"


The downside with this query is that is is selecting all records greater than today and then I have to examine each record to see if the "Talk Date" field has the same week number.



Results



Now, my script syntax supports raw SQL loops too. So is it possible using a raw Microsoft Access JET SQL query to:



Select all Away Talks where the Talk Date field is Week X (where Week is week starting Monday)?



I have tried to do a manual test in Access 2016 with the criteria:



SELECT [Away Talks].[Talk Date]
FROM [Away Talks]
WHERE ((DatePart('ww',[Talk Date],'vbMonday')=45));


But I have an error:



Access Error



What am I doing wrong?










share|improve this question













I have no own "script syntax" for my application. It is designed for creating simple reports from a Microsoft Access Database using JET. Here is a simple example:



REQUIRES "Min number of away talks:" AS $iMinNumAwayTalks
LOOP FROM "Home Talks" NODATERANGE WHERE "Last Given" ISMOREOREQUAL "$Today" SORTBY "Last Given"
SHORTDATE_FIELD "Last Given"
TAB =5>
TEXT "Week: "
VARIABLE_FIELD "Last Given" "$iWeekNo#CUSTOMDATE[%W]"
TEXT "$iWeekNo"
$iAwayTalkCount = 0
LOOP FROM "Away Talks" NODATERANGE WHERE "Talk Date" ISMOREOREQUAL "$Today" SORTBY "Talk Date"
VARIABLE_FIELD "Talk Date" "$iAwayWeekNo#CUSTOMDATE[%W]"
IF "$iAwayWeekNo" IS "$iWeekNo"
$iAwayTalkCount = $iAwayTalkCount + 1
END_IF
END_LOOP
TAB =10>
TEXT "# Away: "
TEXT "$iAwayTalkCount"
TAB =15>
TEXT "$iMinNumAwayTalks"
TEXT " Exceed? "
IF "$iAwayTalkCount" ISMORE "$iMinNumAwayTalks"
TEXT "Yes"
END_IF
IF "$iAwayTalkCount" ISLESSOREQUAL "$iMinNumAwayTalks"
TEXT "No"
END_IF
EOL
END_LOOP


It is basically looking at two tables to work out how many records have the same Week Number (beginning Monday) for the specified fields.



My question relates to this query I have used:



LOOP FROM "Away Talks" NODATERANGE WHERE "Talk Date" ISMOREOREQUAL "$Today"  SORTBY "Talk Date"


The downside with this query is that is is selecting all records greater than today and then I have to examine each record to see if the "Talk Date" field has the same week number.



Results



Now, my script syntax supports raw SQL loops too. So is it possible using a raw Microsoft Access JET SQL query to:



Select all Away Talks where the Talk Date field is Week X (where Week is week starting Monday)?



I have tried to do a manual test in Access 2016 with the criteria:



SELECT [Away Talks].[Talk Date]
FROM [Away Talks]
WHERE ((DatePart('ww',[Talk Date],'vbMonday')=45));


But I have an error:



Access Error



What am I doing wrong?







ms-access jet






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 at 10:36









Andrew Truckle

4,68631943




4,68631943








  • 1




    You will need to filter on both year and week as week 01 and 52/53 may cross calendar boundaries. For example, week 2019-01 spans 2018-12-31 to 2019-01-06. Also, there is no week 00.
    – Gustav
    Nov 7 at 12:23










  • @Gustav Ah, these values are from my MFC program and it returns 0 to 51. So I must add 1 to those results. Thanks. And I thought about the year too.
    – Andrew Truckle
    Nov 7 at 12:59














  • 1




    You will need to filter on both year and week as week 01 and 52/53 may cross calendar boundaries. For example, week 2019-01 spans 2018-12-31 to 2019-01-06. Also, there is no week 00.
    – Gustav
    Nov 7 at 12:23










  • @Gustav Ah, these values are from my MFC program and it returns 0 to 51. So I must add 1 to those results. Thanks. And I thought about the year too.
    – Andrew Truckle
    Nov 7 at 12:59








1




1




You will need to filter on both year and week as week 01 and 52/53 may cross calendar boundaries. For example, week 2019-01 spans 2018-12-31 to 2019-01-06. Also, there is no week 00.
– Gustav
Nov 7 at 12:23




You will need to filter on both year and week as week 01 and 52/53 may cross calendar boundaries. For example, week 2019-01 spans 2018-12-31 to 2019-01-06. Also, there is no week 00.
– Gustav
Nov 7 at 12:23












@Gustav Ah, these values are from my MFC program and it returns 0 to 51. So I must add 1 to those results. Thanks. And I thought about the year too.
– Andrew Truckle
Nov 7 at 12:59




@Gustav Ah, these values are from my MFC program and it returns 0 to 51. So I must add 1 to those results. Thanks. And I thought about the year too.
– Andrew Truckle
Nov 7 at 12:59












2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










You provide vbMonday in your query as a string literal ('vbMonday'), instead of a numeric value.



Unfortunately you can't use the VBA constant vbMonday in a query, so you would have to use its numeric equivalent: 2



To find out this numeric value yourself you can enter ?vbMonday in the VBEs immediate window, or open the 'Object Browser' window for example by pressing F2 in the VBE.
There you could search for vbMonday and see it's numeric value at the bottom of the window.






share|improve this answer























  • I saw the value of 2 in the help where it listed the parameters. When I get home I will give your suggestion a try. Thank you.
    – Andrew Truckle
    Nov 7 at 12:18






  • 1




    Right, the documentation/help also is a good source of information. Always. ;-)
    – Unhandled Exception
    Nov 7 at 12:38


















up vote
1
down vote













Your criteria in the query design window is supplying a week number not a date so you need to create the week no field to apply the criteria to - try pasting your code into the SQL query editor



SELECT [Away Talks].[Talk Date]
FROM [Away Talks]
WHERE ((DatePart('ww',[Talk Date], 2)=45));


See below






share|improve this answer























  • My criteria was correct. The field itself is the date and I was extracting the week number from it and comparing it against a specific week number for test purposes. I suggest this answer is deleted and it is not correct. The reason was as stated in the other answer. Ironically in your example you have done it right and used 2 instead of vbMonday anyway. That is all it was.
    – Andrew Truckle
    Nov 7 at 17:23






  • 1




    Your criteria and SQL was correct - But in the picture posted of the design window you are applying the criteria to the date field, not the calculated week value. If you open the query editor with your correct SQL you will see it is applied in a different way in the query view. That is why you got the Data Mismatch - which was your original question.
    – Minty
    Nov 7 at 17:31








  • 1




    Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
    – Andrew Truckle
    Nov 7 at 17:49










  • Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
    – Andrew Truckle
    Nov 7 at 17:49











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53187736%2fsql-query-to-select-records-where-date-field-is-certain-week-number%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










You provide vbMonday in your query as a string literal ('vbMonday'), instead of a numeric value.



Unfortunately you can't use the VBA constant vbMonday in a query, so you would have to use its numeric equivalent: 2



To find out this numeric value yourself you can enter ?vbMonday in the VBEs immediate window, or open the 'Object Browser' window for example by pressing F2 in the VBE.
There you could search for vbMonday and see it's numeric value at the bottom of the window.






share|improve this answer























  • I saw the value of 2 in the help where it listed the parameters. When I get home I will give your suggestion a try. Thank you.
    – Andrew Truckle
    Nov 7 at 12:18






  • 1




    Right, the documentation/help also is a good source of information. Always. ;-)
    – Unhandled Exception
    Nov 7 at 12:38















up vote
3
down vote



accepted










You provide vbMonday in your query as a string literal ('vbMonday'), instead of a numeric value.



Unfortunately you can't use the VBA constant vbMonday in a query, so you would have to use its numeric equivalent: 2



To find out this numeric value yourself you can enter ?vbMonday in the VBEs immediate window, or open the 'Object Browser' window for example by pressing F2 in the VBE.
There you could search for vbMonday and see it's numeric value at the bottom of the window.






share|improve this answer























  • I saw the value of 2 in the help where it listed the parameters. When I get home I will give your suggestion a try. Thank you.
    – Andrew Truckle
    Nov 7 at 12:18






  • 1




    Right, the documentation/help also is a good source of information. Always. ;-)
    – Unhandled Exception
    Nov 7 at 12:38













up vote
3
down vote



accepted







up vote
3
down vote



accepted






You provide vbMonday in your query as a string literal ('vbMonday'), instead of a numeric value.



Unfortunately you can't use the VBA constant vbMonday in a query, so you would have to use its numeric equivalent: 2



To find out this numeric value yourself you can enter ?vbMonday in the VBEs immediate window, or open the 'Object Browser' window for example by pressing F2 in the VBE.
There you could search for vbMonday and see it's numeric value at the bottom of the window.






share|improve this answer














You provide vbMonday in your query as a string literal ('vbMonday'), instead of a numeric value.



Unfortunately you can't use the VBA constant vbMonday in a query, so you would have to use its numeric equivalent: 2



To find out this numeric value yourself you can enter ?vbMonday in the VBEs immediate window, or open the 'Object Browser' window for example by pressing F2 in the VBE.
There you could search for vbMonday and see it's numeric value at the bottom of the window.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 7 at 10:59

























answered Nov 7 at 10:53









Unhandled Exception

62436




62436












  • I saw the value of 2 in the help where it listed the parameters. When I get home I will give your suggestion a try. Thank you.
    – Andrew Truckle
    Nov 7 at 12:18






  • 1




    Right, the documentation/help also is a good source of information. Always. ;-)
    – Unhandled Exception
    Nov 7 at 12:38


















  • I saw the value of 2 in the help where it listed the parameters. When I get home I will give your suggestion a try. Thank you.
    – Andrew Truckle
    Nov 7 at 12:18






  • 1




    Right, the documentation/help also is a good source of information. Always. ;-)
    – Unhandled Exception
    Nov 7 at 12:38
















I saw the value of 2 in the help where it listed the parameters. When I get home I will give your suggestion a try. Thank you.
– Andrew Truckle
Nov 7 at 12:18




I saw the value of 2 in the help where it listed the parameters. When I get home I will give your suggestion a try. Thank you.
– Andrew Truckle
Nov 7 at 12:18




1




1




Right, the documentation/help also is a good source of information. Always. ;-)
– Unhandled Exception
Nov 7 at 12:38




Right, the documentation/help also is a good source of information. Always. ;-)
– Unhandled Exception
Nov 7 at 12:38












up vote
1
down vote













Your criteria in the query design window is supplying a week number not a date so you need to create the week no field to apply the criteria to - try pasting your code into the SQL query editor



SELECT [Away Talks].[Talk Date]
FROM [Away Talks]
WHERE ((DatePart('ww',[Talk Date], 2)=45));


See below






share|improve this answer























  • My criteria was correct. The field itself is the date and I was extracting the week number from it and comparing it against a specific week number for test purposes. I suggest this answer is deleted and it is not correct. The reason was as stated in the other answer. Ironically in your example you have done it right and used 2 instead of vbMonday anyway. That is all it was.
    – Andrew Truckle
    Nov 7 at 17:23






  • 1




    Your criteria and SQL was correct - But in the picture posted of the design window you are applying the criteria to the date field, not the calculated week value. If you open the query editor with your correct SQL you will see it is applied in a different way in the query view. That is why you got the Data Mismatch - which was your original question.
    – Minty
    Nov 7 at 17:31








  • 1




    Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
    – Andrew Truckle
    Nov 7 at 17:49










  • Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
    – Andrew Truckle
    Nov 7 at 17:49















up vote
1
down vote













Your criteria in the query design window is supplying a week number not a date so you need to create the week no field to apply the criteria to - try pasting your code into the SQL query editor



SELECT [Away Talks].[Talk Date]
FROM [Away Talks]
WHERE ((DatePart('ww',[Talk Date], 2)=45));


See below






share|improve this answer























  • My criteria was correct. The field itself is the date and I was extracting the week number from it and comparing it against a specific week number for test purposes. I suggest this answer is deleted and it is not correct. The reason was as stated in the other answer. Ironically in your example you have done it right and used 2 instead of vbMonday anyway. That is all it was.
    – Andrew Truckle
    Nov 7 at 17:23






  • 1




    Your criteria and SQL was correct - But in the picture posted of the design window you are applying the criteria to the date field, not the calculated week value. If you open the query editor with your correct SQL you will see it is applied in a different way in the query view. That is why you got the Data Mismatch - which was your original question.
    – Minty
    Nov 7 at 17:31








  • 1




    Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
    – Andrew Truckle
    Nov 7 at 17:49










  • Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
    – Andrew Truckle
    Nov 7 at 17:49













up vote
1
down vote










up vote
1
down vote









Your criteria in the query design window is supplying a week number not a date so you need to create the week no field to apply the criteria to - try pasting your code into the SQL query editor



SELECT [Away Talks].[Talk Date]
FROM [Away Talks]
WHERE ((DatePart('ww',[Talk Date], 2)=45));


See below






share|improve this answer














Your criteria in the query design window is supplying a week number not a date so you need to create the week no field to apply the criteria to - try pasting your code into the SQL query editor



SELECT [Away Talks].[Talk Date]
FROM [Away Talks]
WHERE ((DatePart('ww',[Talk Date], 2)=45));


See below







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 7 at 17:36

























answered Nov 7 at 11:33









Minty

1,4821411




1,4821411












  • My criteria was correct. The field itself is the date and I was extracting the week number from it and comparing it against a specific week number for test purposes. I suggest this answer is deleted and it is not correct. The reason was as stated in the other answer. Ironically in your example you have done it right and used 2 instead of vbMonday anyway. That is all it was.
    – Andrew Truckle
    Nov 7 at 17:23






  • 1




    Your criteria and SQL was correct - But in the picture posted of the design window you are applying the criteria to the date field, not the calculated week value. If you open the query editor with your correct SQL you will see it is applied in a different way in the query view. That is why you got the Data Mismatch - which was your original question.
    – Minty
    Nov 7 at 17:31








  • 1




    Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
    – Andrew Truckle
    Nov 7 at 17:49










  • Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
    – Andrew Truckle
    Nov 7 at 17:49


















  • My criteria was correct. The field itself is the date and I was extracting the week number from it and comparing it against a specific week number for test purposes. I suggest this answer is deleted and it is not correct. The reason was as stated in the other answer. Ironically in your example you have done it right and used 2 instead of vbMonday anyway. That is all it was.
    – Andrew Truckle
    Nov 7 at 17:23






  • 1




    Your criteria and SQL was correct - But in the picture posted of the design window you are applying the criteria to the date field, not the calculated week value. If you open the query editor with your correct SQL you will see it is applied in a different way in the query view. That is why you got the Data Mismatch - which was your original question.
    – Minty
    Nov 7 at 17:31








  • 1




    Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
    – Andrew Truckle
    Nov 7 at 17:49










  • Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
    – Andrew Truckle
    Nov 7 at 17:49
















My criteria was correct. The field itself is the date and I was extracting the week number from it and comparing it against a specific week number for test purposes. I suggest this answer is deleted and it is not correct. The reason was as stated in the other answer. Ironically in your example you have done it right and used 2 instead of vbMonday anyway. That is all it was.
– Andrew Truckle
Nov 7 at 17:23




My criteria was correct. The field itself is the date and I was extracting the week number from it and comparing it against a specific week number for test purposes. I suggest this answer is deleted and it is not correct. The reason was as stated in the other answer. Ironically in your example you have done it right and used 2 instead of vbMonday anyway. That is all it was.
– Andrew Truckle
Nov 7 at 17:23




1




1




Your criteria and SQL was correct - But in the picture posted of the design window you are applying the criteria to the date field, not the calculated week value. If you open the query editor with your correct SQL you will see it is applied in a different way in the query view. That is why you got the Data Mismatch - which was your original question.
– Minty
Nov 7 at 17:31






Your criteria and SQL was correct - But in the picture posted of the design window you are applying the criteria to the date field, not the calculated week value. If you open the query editor with your correct SQL you will see it is applied in a different way in the query view. That is why you got the Data Mismatch - which was your original question.
– Minty
Nov 7 at 17:31






1




1




Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
– Andrew Truckle
Nov 7 at 17:49




Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
– Andrew Truckle
Nov 7 at 17:49












Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
– Andrew Truckle
Nov 7 at 17:49




Ah, yes, I did notice this when I went from the corrected SQL view to the design view. So I will up-vote your answer. Thank you.
– Andrew Truckle
Nov 7 at 17:49


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53187736%2fsql-query-to-select-records-where-date-field-is-certain-week-number%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings