I'm not from A Microsoft SQL server world but have recently made that transition. I am drawing a blank on how to get what I need out of the database.
I have a single table with a subquery to get an id from another table within it.
This is working great and returns every value that is within the date range:
The problem is this is a scheduling program that allows for recurring scheduling. The program throws all the scheduled items in the table at the time the user makes the schedule. I have a separate table that holds the scheduling pattern.
What I would like to show one record for each distinct PeripheralMapID (which I use to get the name in a different query). I have tried SELECT DISTINCT, however cannot get it to return a distinct value, even when I reduce the query to
I'm very new at MSSQL and my brain is fried from the full week I've had already. If some one can show me the correct syntax I would be very grateful. I'm sure it's something simple. I've tried to find the answer on the net and developer forums but cannot find. So I'm asking you for help!
Thank you!
"If the only prayer you said in
your whole life was, 'thank you,'
that would suffice."
-- Meister Eckhart
I have a single table with a subquery to get an id from another table within it.
Code:
SELECT PeripheralMapID, MaintID, ScheduleID, MaintenanceFlag, MaintenanceTypeID,
(SELECT Schedule.ScheduleOcccurenceID
FROM Schedule
WHERE Maintenance.ScheduleID = Schedule.ScheduleID) AS occur_id, MaintenanceStartTime AS StartTime, MaintenanceEndTime AS EndTime,
DayOfWeek, ModifiedBy, DateModified
FROM Maintenance
WHERE (MaintenanceStartTime > GETDATE())
Hoffman Estates ASR08 Nov 2 2007 8:00PM Nov 3 2007 7:00AM Nov 2 2007 4:30PM sa
Hoffman Estates ASR08 Nov 5 2007 8:00PM Nov 6 2007 7:00AM Nov 2 2007 4:30PM sa
Hoffman Estates ASR08 Nov 6 2007 8:00PM Nov 7 2007 7:00AM Nov 2 2007 4:30PM sa
Hoffman Estates ASR08 Nov 7 2007 8:00PM Nov 8 2007 7:00AM Nov 2 2007 4:30PM sa
Troy ASR20 Nov 3 2007 9:00PM Dec 4 2007 11:59AM Nov 2 2007 4:31PM sa
Troy ASR20 Dec 1 2007 9:00PM Dec 2 2007 11:59AM Nov 2 2007 4:31PM sa
.........
The problem is this is a scheduling program that allows for recurring scheduling. The program throws all the scheduled items in the table at the time the user makes the schedule. I have a separate table that holds the scheduling pattern.
What I would like to show one record for each distinct PeripheralMapID (which I use to get the name in a different query). I have tried SELECT DISTINCT, however cannot get it to return a distinct value, even when I reduce the query to
Code:
SELECT DISTINCT PeripheralMapID from Maintenance
I'm very new at MSSQL and my brain is fried from the full week I've had already. If some one can show me the correct syntax I would be very grateful. I'm sure it's something simple. I've tried to find the answer on the net and developer forums but cannot find. So I'm asking you for help!
Thank you!
"If the only prayer you said in
your whole life was, 'thank you,'
that would suffice."
-- Meister Eckhart