rakesh_rl
asked on
How to frame a date check query
Please let me know the syntax for retrieving the list of devices for a given date (@input_date_by_user)
where the EARLIEST device_start_ date of the device is less than the @input_date_by_user. (from device table). Is it something to with HAVING clause, I have other where conditions too.
where the EARLIEST device_start_ date of the device is less than the @input_date_by_user. (from device table). Is it something to with HAVING clause, I have other where conditions too.
ASKER
I have multiple start dates for the same device (based on location) so I have to take the earliest.
Try this?
select devices,min(device_start_d ate) from [device_table] where device_start_ date < @input_date_by_user group by devices
select devices,min(device_start_d
ASKER
This will not work as I need this check to be done in the where clause.
In the snippet, I want something like
min(device.date_of_effect ) <= '01/01/2008'
instead of
device.date_of_effect <= '01/01/2008'
In the snippet, I want something like
min(device.date_of_effect ) <= '01/01/2008'
instead of
device.date_of_effect <= '01/01/2008'
SELECT *
FROM device,
SRO
WHERE SRO.location_name = 'ABC' and
device.date_of_effect <= '01/01/2008' and
device.SRO_id = SRO.SRO_id AND
device.device_type = 'Electronic'
What is this? FROM device,
SRO ---you must find the join for these tables otherwise it's union all (many combinations)
and select * is bad practice call your variables implicitly please.
It does work on simpler mock up tables I've tested it for you! Your where clauses will have no impact on "group by"
for each variable you need add it to group by list (try code below)
SRO ---you must find the join for these tables otherwise it's union all (many combinations)
and select * is bad practice call your variables implicitly please.
It does work on simpler mock up tables I've tested it for you! Your where clauses will have no impact on "group by"
for each variable you need add it to group by list (try code below)
SELECT sro.location_name,min(dv.date_of_effect),dv.devicetype
FROM device dv left join SRO on dv.SRO_id = SRO.SRO_id
WHERE SRO.location_name = 'ABC' and
dv.date_of_effect <= '01/01/2008' and
dv.device_type = 'Electronic'
GROUP BY dv.devicetype,sro.location_name
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This works. Thank you.
Glad to be of help :)
where the EARLIEST device_start_ date of the device is less than the @input_date_by_user. (from device table). "
select devices from [device_table] where device_start_ date < @input_date_by_user