Jump to content
  • 0

Date ranges are not working in sql quries


Mushigee2266

Question

I am filtering data with many fields and date is one of them. I have added date criteria which is filtering data accurately. My problem is this , I am using calculating fields on results page and using this criteria on that as shown below in sql code. But it is not working. Please check the code and send me solution if any

I am receiving DateFrom in calcfields3 and DateTo in Calfield4 on results page and then use them in the code

ISNULL(((SELECT COUNT (Master_Data_Auto_Condition_Validation) FROM _v_Master_Data_Auto_102522
 WHERE Master_Data_Auto_Category=Target.[@field:Master_Data_Auto_Category] AND Master_Data_Auto_Condition_Validation>=0 AND Master_Data_Auto_Indice=target.[@field:Master_Data_Auto_Indice] AND Master_Data_Auto_Condition_Description=target.[@field:Master_Data_Auto_Condition_Description] and Master_Data_Auto_Date>=[@calcfield:3] and Master_Data_Auto_Date<=[@calcfield:4] )),0)

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

You can try to use something like this: 
SELECT * FROM Orders
WHERE OrderDate BETWEEN '1996-07-01' AND '1996-07-31';

In your case: 
Note that the date format should match for Master_Data_Auto_Date, [@calcfield:3] and [@calcfield:4]

ISNULL(((SELECT COUNT (Master_Data_Auto_Condition_Validation) 
FROM _v_Master_Data_Auto_102522
WHERE Master_Data_Auto_Category=Target.[@field:Master_Data_Auto_Category] 
AND Master_Data_Auto_Condition_Validation>=0 
AND Master_Data_Auto_Indice=target.[@field:Master_Data_Auto_Indice] 
AND Master_Data_Auto_Condition_Description=target.[@field:Master_Data_Auto_Condition_Description] 
AND Master_Data_Auto_Date BETWEEN [@calcfield:3] and [@calcfield:4] )),0)
Link to comment
Share on other sites

  • 0
On 10/28/2022 at 8:22 PM, Mushigee2266 said:

I am filtering data with many fields and date is one of them. I have added date criteria which is filtering data accurately. My problem is this , I am using calculating fields on results page and using this criteria on that as shown below in sql code. But it is not working. Please check the code and send me solution if any

I am receiving DateFrom in calcfields3 and DateTo in Calfield4 on results page and then use them in the code

ISNULL(((SELECT COUNT (Master_Data_Auto_Condition_Validation) FROM _v_Master_Data_Auto_102522
 WHERE Master_Data_Auto_Category=Target.[@field:Master_Data_Auto_Category] AND Master_Data_Auto_Condition_Validation>=0 AND Master_Data_Auto_Indice=target.[@field:Master_Data_Auto_Indice] AND Master_Data_Auto_Condition_Description=target.[@field:Master_Data_Auto_Condition_Description] and Master_Data_Auto_Date>=[@calcfield:3] and Master_Data_Auto_Date<=[@calcfield:4] )),0)

You may also try to convert calculated fields 3 and  4 to DateTime.

ISNULL(((SELECT COUNT (Master_Data_Auto_Condition_Validation) FROM _v_Master_Data_Auto_102522
 WHERE Master_Data_Auto_Category=Target.[@field:Master_Data_Auto_Category] AND Master_Data_Auto_Condition_Validation>=0 AND Master_Data_Auto_Indice=target.[@field:Master_Data_Auto_Indice] AND Master_Data_Auto_Condition_Description=target.[@field:Master_Data_Auto_Condition_Description] and Master_Data_Auto_Date>=(CONVERT(DATETIME, [@calcfield:3], 101)) and Master_Data_Auto_Date<=(CONVERT(DATETIME, [@calcfield:4], 101)))),0)
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...