imak
(Ian Mak)
June 18, 2024, 2:19pm
1
Hi all,
I’ve got a solution already but just wondering if there is a cleaner way to doing this?
I need a query that tells me what stock is aged.
Aged stock = Anything 1+ year old.
I’ve queried the PartLot table and found the FirstRefDate which I will be working off.
First calculated field - Today’s date converted to an int. No issue here.
convert(int,getdate())
Second calculated field - FirstRefDate converted to an int
I get an error if I try convert FirstRefDate to int:
What?!
Instead, if I convert to DateTime format first it works:
Final calculated field - Tag anything over 365 days as “aged”
It works. Just feels… messy. Any tips or is this the best solution?
Ian
dcamlin
(David Camlin)
June 18, 2024, 2:26pm
2
Not that its THAT much cleaner… but I think you can compound your converts. Put one inside the other.
1 Like
dcamlin
(David Camlin)
June 18, 2024, 2:30pm
3
Along those same lines… once you get the result you want in situations like this, I always like to see if I can combine it all into (1) calc field…
Try it out… looks like you could:
… unless you need the substeps as available columns, that is.
4 Likes
knash
(Ken Nash)
June 18, 2024, 2:42pm
4
Might be better to use the datediff sql function and only use one field.
datediff(day,PartLot.FirstRefDate,getdate())
This returns the number of days between the two dates.
then you can query where the date is greater than 365 days… just a thought.
5 Likes
imak
(Ian Mak)
June 18, 2024, 3:01pm
5
Thank you David and Ken for those tips! Will give them a try!
1 Like