两个查询都一样吗?两者返回相同的结果吗?
1)
IF EXISTS( SELECT 1 FROM Users u WHERE u.UPIN = @AttendingDoctorID) BEGIN SELECT u.UserId, 1 FROM Users u WITH(nolock) WHERE u.UPIN = @AttendingDoctorID END ELSE BEGIN SELECT u.UserId, 1 FROM Users u (nolock) WHERE u.FirstName = @AttendingDoctorFirstName AND u.LastName = @AttendingDoctorLastName END
2)
SELECT u.UserId, 1 FROM Users u (nolock) WHERE (u.UPIN = @AttendingDoctorID) OR (u.FirstName = @AttendingDoctorFirstName AND u.LastName = @AttendingDoctorLastName)
它们不一样。