다음 SQL 쿼리에 문제가 있습니다. 조건이 작동하지 않고이 쿼리를 실행할 때 ...하지만 조건을 사용할 때 작동하지 않을 때 다음과 같은 오류 메시지가 나타납니다 ..where 조건 SQL PIVOT
'수준 137, 수준 15, 상태 2, 줄 4 스칼라 변수 "@ courseid1"을 (를) 선언해야합니다.'
ALTER PROCEDURE [dbo].[SP_Attendance]
@courseid as int=null, @subjid int=null
AS
Declare @colList varchar(max)
Declare @qry varchar(max)
Declare @courseid1 as [email protected],
@subjid1 [email protected]
SET @colList = STUFF((SELECT distinct ',' + QUOTENAME(SA.Attend_Date)
FROM Student_Attendance_Sheet SA
FOR XML PATH(''), TYPE
).value('/', 'NVARCHAR(MAX)')
,1,1,'')
SET @qry = 'SELECT Roll_No, EnrollmentNo, STUD_FNAME + STUD_MNAME + STUD_LNAME as [Student Name] , '[email protected]+'
FROM (
select SA.Roll_No, SA.Attend_Date, SA.Attendance from Student_Attendance_Sheet SA
where (SA.Course_ID = [email protected]+) and (SA.Subject_ID = [email protected]+)
) as s
PIVOT
(
MAX(Attendance)
FOR Attend_Date IN (' + @colList + ')
) pvt '
print(@qry)
Exec(@qry)
간부 SP_Attendance 2,
3 한가지 더 .. 내가 사용하고있는 곳은 작동하지만 거기에는 필터링이 .. 없다 그래서 나는 어디에 사용해야
SET @colList = STUFF((SELECT distinct ',' + QUOTENAME(SA.Attend_Date)
FROM Student_Attendance_Sheet SA
where (SA.Course_ID = [email protected]+) and (SA.Subject_ID = [email protected]+)
FOR XML PATH(''), TYPE
).value('/', 'NVARCHAR(MAX)')
,1,1,'')
의 조건 위의 방식으로 조건 ... 이 문제를 해결하는 데 도움주세요 ... 감사합니다