الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ماذا عن الخطا فى هذه function

بدأه shosho842000 في 3 مايو 2010 · 3 رد · 747 مشاهدة · في قواعد بيانات Microsoft SQL Server
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمته الله وبركاته

ماذا عن الخطا فى هذه function حيث اقوم بجلب رقم الموظف والدرجة الماليه له والمرتب واقوم بحساب الضريبه بنائ على الدرجة

CREATE FUNCTION salarycalc (@degree int,@salary float)
(	
@date datetime ,
@tax float 
)
RETURNS TABLE 
AS
RETURN 
(

	if exists (select id,sal1,sal2,sal4,sal5,sal6,sal7,sal8,sal9,sal10,sal11,sal12,sal13,sal14,sal15,sal16,sal17,sal18,sal19 from salary where date=@date)
    begin 
SELECT     dbo.emp_degree.emp_id, dbo.emp_degree.sal_name, dbo.degree.name, dbo.salary.sal3
FROM         dbo.degree INNER JOIN
                      dbo.emp_degree ON dbo.degree.id = dbo.emp_degree.sal_name 
                     INNER JOIN dbo.salary ON dbo.emp_degree.emp_id = dbo.salary.id
if dbo.emp_degree.sal_name = 'الدرجة الاولى' then 
set @tax =(@salary * 10) \ 100 
else if dbo.emp_degree.sal_name = 'الدرجة الثانية' then 
set @tax =(@salary * 7) \ 100 
end if

end

هذا هو الخطا

Msg 102, Level 15, State 1, Procedure salarycalc, Line 7

Incorrect syntax near '('.

Msg 137, Level 15, State 2, Procedure salarycalc, Line 18

Must declare the scalar variable "@date".

Msg 156, Level 15, State 1, Procedure salarycalc, Line 24

Incorrect syntax near the keyword 'then'.

Msg 102, Level 15, State 1, Procedure salarycalc, Line 25

Incorrect syntax near '\100'.

Msg 156, Level 15, State 1, Procedure salarycalc, Line 26

Incorrect syntax near the keyword 'then'.

Msg 102, Level 15, State 1, Procedure salarycalc, Line 27

Incorrect syntax near '\100'.

وشكرا

#2

shosho842000 كتب:

السلام عليكم ورحمته الله وبركاته

ماذا عن الخطا فى هذه function حيث اقوم بجلب رقم الموظف والدرجة الماليه له والمرتب واقوم بحساب الضريبه بنائ على الدرجة


(
@date datetime ,
@tax float
)
RETURNS TABLE
AS
RETURN
(

if exists (select id,sal1,sal2,sal4,sal5,sal6,sal7,sal8,sal9,sal10,sal11,sal12,sal13,sal14,sal15,sal16,sal17,sal18,sal19 from salary where date=@date)
begin
SELECT dbo.emp_degree.emp_id, dbo.emp_degree.sal_name, dbo.degree.name, dbo.salary.sal3
FROM dbo.degree INNER JOIN
dbo.emp_degree ON dbo.degree.id = dbo.emp_degree.sal_name
INNER JOIN dbo.salary ON dbo.emp_degree.emp_id = dbo.salary.id
if dbo.emp_degree.sal_name = 'الدرجة الاولى' then
set @tax =(@salary * 10) \ 100
else if dbo.emp_degree.sal_name = 'الدرجة الثانية' then
set @tax =(@salary * 7) \ 100
end if

end
CREATE FUNCTION salarycalc (@degree int,@salary float)

هذا هو الخطا

Msg 102, Level 15, State 1, Procedure salarycalc, Line 7

Incorrect syntax near '('.

Msg 137, Level 15, State 2, Procedure salarycalc, Line 18

Must declare the scalar variable "@date".

Msg 156, Level 15, State 1, Procedure salarycalc, Line 24

Incorrect syntax near the keyword 'then'.

Msg 102, Level 15, State 1, Procedure salarycalc, Line 25

Incorrect syntax near '\100'.

Msg 156, Level 15, State 1, Procedure salarycalc, Line 26

Incorrect syntax near the keyword 'then'.

Msg 102, Level 15, State 1, Procedure salarycalc, Line 27

Incorrect syntax near '\100'.

وشكرا

اخي الكريم ,

صيغة الاقتران كلها خطأ

صيغة الاقتران في ال SQL server

تكون كالاتي

CREATE FUNCTION [ schema_name. ] function_name
( [ { @parameter_name [ AS ] [ type_schema_name. ] parameter_data_type
[ = default ] }
[ ,...n ]
]
)
RETURNS @return_variable TABLE < table_type_definition >
[ WITH <function_option> [ ,...n ] ]
[ AS ]
BEGIN
function_body
RETURN
END [ ; ]

والجملة الشرطية تكون صيغتها

if
begin

end

اعذرني لأنني لم استطع كتابة الكود الخاص بك, لأن ال SQL server غير موجودة عندي.

#3

اولا شكرا للاخ الفاضل على الرد ولكن اريد زيادة فى التوضيح لانى اول مرة استخدم الfunction

ممكن حد يصحح الكود او يشرح بتفضيل اكثر

وشكراااااااااااااا

#4

السلام عليكم

ال function في SQL server بشكل عام مثل الموجود في لغات البرمجة لذا يجب ان يقوم بارجاع قيمة واحدة او جدول . فهل هذا ينطبق هنا ؟

مواضيع مشابهة