私は行き詰まっています。
次のクエリを実行すると、機能します。
select DISTINCT l.Seating_Capacity - (select count(*)
from tblTrainings t1, tbllocations l
where l.locationId = t1.LocationId) as
availableSeats
from tblTrainings t1, tbllocations l
where l.locationId = t1.LocationId
ただし、Seating_Capacity - 上記の合計数 = 0 の場合は「FULL」メッセージを表示するという CASE ステートメントを追加したいと考えています。
それ以外の場合は、残りの数を表示します。
そのクエリは次のとおりです。
select DISTINCT case when l.Seating_Capacity - (select count(*)
from tblTrainings t1, tbllocations l
where l.locationId = t1.LocationId) = 0 then 'full' else STR(Seating_Capacity) end)
availableSeats
from tblTrainings t1, tbllocations l
where l.locationId = t1.LocationId
「End」の近くにある「Incorrect syntax near ')」を取得しています
内部の Seating_Capacity が無効な列名であるというエラーも表示されます。
どうぞよろしくお願いいたします。
テスト中に動いていると思っていたので、夢の国にいたに違いありません。
現在、アプリはライブですが、機能していません。
事前にどうもありがとう
select DISTINCT l.LocationId,c.courseId, c.coursename, l.Seating_Capacity - (select count(*)
from tblTrainings t1
where l.locationId = t1.LocationId and c.courseId = t1.courseId) as
availableSeats,d.dateid,d.trainingDates,d.trainingtime,c.CourseDescription,
i.instructorName,l.location,l.seating_capacity
from tblLocations l
Inner Join tblCourses c on l.locationId = c.locationId
left join tblTrainings t on l.locationId = t.LocationId and c.courseId = t.courseId
Inner Join tblTrainingDates d on c.dateid=d.dateid
Inner Join tblCourseInstructor ic on c.courseId = ic.CourseId
Inner Join tblInstructors i on ic.instructorId = i.instructorId
WHERE CONVERT(VARCHAR(10), d.trainingDates, 101) >= CONVERT(VARCHAR(10), GETDATE(), 101)