السلام عليكم ورحمة منه وبركاته
مشكلتي هي ان الكود التالي لا ينطبق علي اكثر من سجل وانما يعمل علي سجل واحد
ياليت تساعدوني بحل الله يجزيكم كل خير
DECLARE @MothersId int set @MothersId=1036 DECLARE @dateofbirth datetime DECLARE @currentdatetime DATETIME DECLARE @years VARCHAR(40) DECLARE @months VARCHAR(30) DECLARE @days VARCHAR(30) DECLARE @SonId int DECLARE @SonYatem int=0 DECLARE @SonMoal int=0 DECLARE @SonStudyMoal int=0 SET @years=(select datediff(year, DateBirth, GETDATE()) from Deceased_Sons where MothersId=@MothersId)--birthdate SET @months=(select datediff(month, DateBirth, GETDATE()) - (datediff(year, DateBirth, GETDATE()) * 12) from Deceased_Sons where MothersId=@MothersId) set @days=(select datepart(d, GETDATE()) - datepart(d, DateBirth)from Deceased_Sons where MothersId=@MothersId ) if @years<=18 set @SonYatem=+1 if @years>18 and @years<=20 set @SonMoal=+1 if @years>20 and @years<=22 set @SonStudyMoal=+1 select @SonYatem,@SonMoal,@SonStudyMoal