❔ SQL query
Hey guys I have column Date which sometimes have int sometimes strings and sometimes dates
In format --2022-01-26 this indicates when last time the column was updated
So if I have dates
--2022-04-04
--2016-04-04
And I input date
2018 I want to get 2016
2023 I want to get only 2022 as latest
2015 nothing because it wasnt updated yet having hard time with this to work properly
23 Replies
wat
oh, I see
wow, I don't think that could have been worded any worse
What if it's gonna be string or int in my date? How to get only dates
convert anything that's a string to a date
what the hell database is this that allows mixed-type columns?
Commercial one
which one?
why do you have a column that can hold multiple different types of data?
that's just bad design
we'll need to know what database engine you're using so we have a hope of kludging together a working query
like, this level of kludge
i didn't test that, but it would be something like that for sql server
the right solution is to yell at whoever designed your database
It's designed by enova erp ecosystem it's my first week on that job
SQL server
First week as .net developer ever
so, the column type is
sql_variant
?I'm on my phone now, don't know whats column type but you have random numbers there or strings or dates with ~~YYYY-MM-DD
i'm gonna guess it's just a text column
same
which is why we're going to wait for confirmation
waiting is boring
but more productive than working based on guesses
It's like when you add new row first row showing you date ~~YYYY-MM-DD of update and second row showing duplicated contrahent ID which is none available in row with date where it was updated they have priority numbers like 0 is newest so to get contrahentID you need to get that row with priority number and get contrahentID from row which has -1 priority number
that's what I'm gonna do, anyway
when you have access, look at the table and tell us what the actual column type is
Yeah it's probably text column that's why they adding ~~ before date?
Will do sorry for that messy explanation
then you will query against that table to determine exactly what all the possible values look like
then you will write an expression to normalize all of those possibilities into whatever type of value you want
presumably
DATE
It's varchar
lovely
Guys I went on gym and with fresh mind I made it 💪
With an ERP you're lucky it's not an EAV system
o7
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.