السلام عليكم
ما الخطا في كود الفانكشن
كود1: كود
create function func_b(@topicId int, @threadId int) returns table as BEGIN declare @table int if not exists(select count(topicId) from topics where topicId = @topicId) print 'Topic Not Found...!' else if not exists(select count(threadId) from threads where threadId = @threadId) print 'Thread Not Found...!' else set @table =(select MessageSubject, MessageText from Messages where threadId = @threadId) return @table END
---------------
رسالة الخطا هي على الشكل التالي:
Server: Msg 170, Level 15, State 31, Procedure func_b, Line 17
Line 17: Incorrect syntax near 'BEGIN'.
-----------------------------------------------------------------------
كود 2: كود
create function func_b(@topicId int, @threadId int) returns table as begin declare @RecCount int declare @Tbl table if not exists(select count(topicId) from topics where topicId = @topicId) print 'Topic Not Found...!' else begin if not exists(select count(threadId) from threads where topicId = @topicId) print 'Thread Not Found...!' else begin set @Tbl = (select messageSubject, messageText from messages where threadId = @threadId) end end return @Tbl end
---------------
رسائل الخطا هي:
Server: Msg 156, Level 15, State 1, Procedure func_b, Line 7
Incorrect syntax near the keyword 'if'.
Server: Msg 137, Level 15, State 1, Procedure func_b, Line 17
Must declare the variable '@Tbl'.
Server: Msg 137, Level 15, State 1, Procedure func_b, Line 20
Must declare the variable '@Tbl'.
Server: Msg 170, Level 15, State 1, Procedure func_b, Line 22
Line 22: Incorrect syntax near 'BEGIN'.
-----------------------------------------------------------------------
كود 3: كود
Create Function Func_b(@topicId int, @threadId int) RETURNS TABLE AS return if @topicId not in (select topicId from topics) print 'Topic Not Found...!' else if @threadId not in (select threadId from threads) print 'Thread Not Found...!' else (select m.MessageSubject, m.MessageText from Messages m JOIN threads ON m.threadId = threads.threadId JOIN topics ON topics.topicId = threads.topicId WHERE topics.topicID=@topicId and threads.threadId=@threadId)
رسالة الخطا هي:
Server: Msg 156, Level 15, State 1, Procedure Func_b, Line 8
Incorrect syntax near the keyword 'if'.
---------------------------------
اكثر مشكلة واجهتني بكل اشكال الكود .. لحل هذه المسائلة ... و بمختلف الطرق انو عم يطلع خطا اما بالاف if او بالبعن begin او بالاند تبعها end ... يعني ما عم يفهمهون .. انا حاولت حل هل الطلب بس للاسف ما قدرت .. و عن جد الافكار عم تفوت ببعضها ..
و السؤال هو :
اكتب التابع Func_b الذي يعيد موضوع ورسالة كل رسالة تابعة لموضوع رقمه @TopicID ولبند ضمنه رقمه @ThreadID مع معالجة حالات عدم وجود الموضوع وعدم وجود البند ضمن الموضوع.
فارجو المساعدة ، يا شباب انا و الله عم اخذ مساعداتكم و حاول طبقها .. و حتى عم حاول اطلع بحلول .. بس ما عم يضبط معي .. و ما عم اعتمد عليكون بشكل كامل ، يعني مالي اتكالي .. انو انتو تحلولي الطلبات و انا ما اعمل شي .. بس ما عم يطلع معي شي
شكرا جزيلا لكم