我得到'多部分標識符'Membership.Mem_Num「無法綁定。每當我嘗試執行此代碼時出錯:SQL管理工作室中的簡單存儲過程出錯
Alter Proc Procedure1
(
@MemNum int
)
AS
BEGIN
if (@MemNum != Membership.Mem_Num)
Begin
Print 'This Member Number does not exist.'
End
Else
Select @MemNum AS 'MemNum', Movie.Movie_Num, Movie_Title, Movie_Year, Movie_Cost, Movie_Genre ,Price_Code
From Movie, Membership, Video, DetailRental, Rental
Where @MemNum = Membership.Mem_Num AND
Movie.Movie_Num = Video.Movie_Num AND
Video.Vid_Num = DetailRental.Vid_Num AND
DetailRental.Rent_Num = Rental.Rent_Num AND
Rental.Mem_Num = Membership.Mem_Num END
我需要if語句來驗證表中是否存在成員編號。如果沒有,那麼代碼應該打印「成員編號不存在」。但是,我得到的問題是在if(@memnum!= Membership.mem_num)語句中。
COUNT(*)是矯枉過正這裏。替代存在可能是'if(SELECT top(1)0 FROM membership WHERE mem_num = @MemNum)爲空' – Serg
同意。頂部/存在都是更好的替代方法。 –