I’m facing a weird issue and I can’t understand what’s wrong.
In my database I have a datetime field, which keeps some values like: 03.10.2012 11:25:06
I need to convert it to date and compare it with another date. What I have tried without success is:
p1.value as City,
p2.value as Country,
p3.value as RequestNumber,
convert (datetime, convert (varchar, test.timestampmin, 101), 101) as timestampmin
from Process p
LEFT JOIN Parameter p1 on p1.ID=p.id AND p1.NAME = 'City'
LEFT JOIN Parameter p2 on p2.ID=p.id AND p2.NAME = 'Country'
LEFT JOIN PA_Parameter p3 on p3.ID=p.id AND p3.NAME = 'RequestNumber'
INNER JOIN
(
SELECT min(Timestamp) as timestampmin, id as id
FROM tasks
GROUP BY id
) as test
ON test.id = p3.ID
where p.type='Event' and
timestampmin = convert (datetime, convert (varchar, '06.18.2012', 101), 101)
The problem is that I can’t compare the converted datetime with the convert (datetime, convert (varchar, '06.18.2012', 101), 101) which I’m using in the where clause.
What am I missing?
Quite simply, you cannot access column aliases in the SELECT clause within the WHERE clause of the same query.
And if
test.timestampminis a datetime column, you can use this in the WHERE clause instead