Forum Discussion
AmaniMRA
Apr 13, 2022Copper Contributor
SQL condition based on a select subquery column not bounding
Hello, I have a request for help regarding an SQL query that drive me crazy. Using MSSQL, I want to apply a condition based on a select subquery. How can I do it optimally ? Here is my initial q...
olafhelper
Apr 14, 2022Bronze Contributor
AmaniMRA ,
you get the error message because "t." is the query alias for the inner sub-query, the alias for the outer query is tblB =>
WHERE CAST(tlbB.PlacementDate AS DATE) = CAST(getdate() AS DATE)
- AmaniMRAApr 14, 2022Copper Contributor
olafhelperWhen using "tlbB.PlacementDate" it will refer to "TOP 1 PlacementDate" from "tlbB" and so the logic will be "WHERE TOP 1 PlacementDate = today's date" which is not the logic that I'm searching for ( query tested and returning unexpected result ).
The correct logic is : "WHERE PlacementDate ( from the union table ) = today's date". This is what I'm enable to do. Please advise