LindaOKSTATE
asked on
Need records for previous 24 hrs on demand, date and time combined in text filed
02/04/2010 06:44 This is a date-time combined field that is a string. I need to be able to pull records for 24 hrs from demand time. If possible, I would like to exclude nulls and times within the past 4 hrs of the demand. For example, if I demand the report at 14:00 on March 30, I would like all the records from 14:00 March 29 up til 10:00 on March 30.
Thank you,
LindaOKState
Thank you,
LindaOKState
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
musalman:
I am not sure what is meant by "your demand time Field"
I am not sure what is meant by "your demand time Field"
Did you try my suggestion? It would be entered in the record selection formula in CR, and should give you what you described.
FWIW, for musalman's suggestion, DemandDate would be the name of the datetime string field that you mentioned (like {your datetime field} in my suggestion). He appears to be assuming that you're using a stored procedure with a @DEMAND parameter that you use to pass it the "demand time", in a string form. But I don't understand the second part, where it checks to see if @DEMAND - 4 hours is not null. I don't see how it could be null (assuming that @DEMAND is a valid datetime), and there's no check to see if your datetime field is within the "- 4 hour" window. Aside from that, I don't know if the CONVERT functions would work. Normally you use a format like 120 to convert a datetime to a string, but he's trying to convert @DEMAND to a datetime. And if @DEMAND is already a datetime (or maybe even a string that contains a date and time), then you don't need the CONVERT's at all.
James
FWIW, for musalman's suggestion, DemandDate would be the name of the datetime string field that you mentioned (like {your datetime field} in my suggestion). He appears to be assuming that you're using a stored procedure with a @DEMAND parameter that you use to pass it the "demand time", in a string form. But I don't understand the second part, where it checks to see if @DEMAND - 4 hours is not null. I don't see how it could be null (assuming that @DEMAND is a valid datetime), and there's no check to see if your datetime field is within the "- 4 hour" window. Aside from that, I don't know if the CONVERT functions would work. Normally you use a format like 120 to convert a datetime to a string, but he's trying to convert @DEMAND to a datetime. And if @DEMAND is already a datetime (or maybe even a string that contains a date and time), then you don't need the CONVERT's at all.
James
Definitely, I am assuming that he is using Sql Server SP, Hence, It is better to filter the records at database level but this is another story...
Conversion is required because he is concatenating the two string fields.
Conversion is required because he is concatenating the two string fields.
musalman,
Yes, it's better to filter the records on the server, but a formula like the one I posted should be passed to the server as part of the query for the report, so that shouldn't be a problem.
And, FWIW, I don't see anything about concatenating fields. The table field appears to be a string field with the date and time combined. It was never really clear where the "demand time" was coming from (current date and time or user parameter or ...), but I see no reason to think that it was going to be in two strings.
James
Yes, it's better to filter the records on the server, but a formula like the one I posted should be passed to the server as part of the query for the report, so that shouldn't be a problem.
And, FWIW, I don't see anything about concatenating fields. The table field appears to be a string field with the date and time combined. It was never really clear where the "demand time" was coming from (current date and time or user parameter or ...), but I see no reason to think that it was going to be in two strings.
James
ASKER
The date and time is one field formatted as text: 02/04/2010 06:44. There is no demand parameter other than running the report (Current data and time) and thus the data is updated for the last 24 hrs (minus records for the most recent 4 hrs).
Where DemandDate >= DATEADD("dd",-1,CONVERT(DA
AND DATEADD("hh",-4,CONVERT(DA
@Demand is your String Combined Field and DemandDate is your demand time Field.