منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : كيف أستخدم دالة معرفة مسبقاً ضمن الاستعلام؟
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
الصفحات : 1 2
السلام عليكم ورحمة الله وبركاته

عندي هذه الدالة ReplaceString:
كود :
 Public Function ReplaceString(In_Text As String) As String
       Dim X As Long
       Dim strChar As String
       Dim strReturn As String
       strReturn = ""

       For X = 1 To Len(In_Text)
           strChar = Mid(In_Text, X, 1)
           Select Case strChar
               Case "ال"
                   strChar = ""
               Case Chr(243), Chr(240), Chr(245), Chr(246), Chr(242), Chr(241), Chr(248), Chr(250)
                   strChar = ""
           End Select
           strReturn = strReturn & strChar
       Next
       ReplaceString = strReturn
   End Function

 
كيف أقوم باستخدامها ضمن جملة الاستعلام التالية:
كود :
daReplace = New OleDbDataAdapter("Select * From TBooksNames Order By ReplaceString(TitleAuthor)", ConnReplace)


عندما أستخدم الدالة Replace لا تحدث مشكلة:
كود :
daReplace = New OleDbDataAdapter("Select * From TBooksNames Order By REPLACE(TitleAuthor, 'ال', '')", ConnReplace)


ولكن عندما أستخدم دالتي الجديدة ReplaceString تظهر لي رسالة خطأ:
(دالة غير معرفة في التعبير).

فما الحل أيها الإخوة؟
الفكرة ان هذه الدالة معرفة بالنسبة لملف فيجوال بيسيك الحالي لديك فقط وليست اجراء بالنسبة ل SQL
الحل من وجهة نظري ان تجلب السجلات بدون ترتيب ثم ترتبهم بعد ذلك باستخدام LINQ

كود :
       daReplace = New OleDbDataAdapter("Select * From TBooksNames", ConnReplace)
       daReplace.Fill(dtReplace)
       dtReplace = dtReplace.AsEnumerable().OrderBy(Function(x) ReplaceString(x("TitleAuthor"))).CopyToDataTable
PHP كود :
DECLARE @x int;
set @x= (Select ROW_NUMBER() OVER(ORDER BY (SELECT 1)))
DECLARE @
TBooksNames TABLE (id intChrCol nvarchar(255));
insert into @TBooksNames(id,ChrCol)values(@x,(CHAR(243)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(240)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(245)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(246)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(242)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(241)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(248)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(250)))
Select from @TBooksNames;

SELECT id,REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(ChrCol ,(CHAR(243)) ,'X'),(CHAR(240)) ,'X'),
(
CHAR(245)) ,'X'),(CHAR(246)) ,'X'),(CHAR(242)) ,'X'),(CHAR(241)) ,'X'),(CHAR(248)) ,'X'),(CHAR(250)) ,'X') as x FROM @TBooksNames 

بعض التسالي موفق انشاء الله .
(02-11-20, 05:49 PM)Anas Mahmoud كتب : [ -> ]الفكرة ان هذه الدالة معرفة بالنسبة لملف فيجوال بيسيك الحالي لديك فقط وليست اجراء بالنسبة ل SQL
الحل من وجهة نظري ان تجلب السجلات بدون ترتيب ثم ترتبهم بعد ذلك باستخدام LINQ

كود :
       daReplace = New OleDbDataAdapter("Select * From TBooksNames", ConnReplace)
       daReplace.Fill(dtReplace)
       dtReplace = dtReplace.AsEnumerable().OrderBy(Function(x) ReplaceString(x("TitleAuthor"))).CopyToDataTable

للأسف لم تنجح هذه الطريقة

جزاك الله خيراً

(02-11-20, 06:18 PM)asemshahen5 كتب : [ -> ]
PHP كود :
DECLARE @x int;
set @x= (Select ROW_NUMBER() OVER(ORDER BY (SELECT 1)))
DECLARE @
TBooksNames TABLE (id intChrCol nvarchar(255));
insert into @TBooksNames(id,ChrCol)values(@x,(CHAR(243)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(240)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(245)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(246)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(242)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(241)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(248)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(250)))
Select from @TBooksNames;

SELECT id,REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(ChrCol ,(CHAR(243)) ,'X'),(CHAR(240)) ,'X'),
(
CHAR(245)) ,'X'),(CHAR(246)) ,'X'),(CHAR(242)) ,'X'),(CHAR(241)) ,'X'),(CHAR(248)) ,'X'),(CHAR(250)) ,'X') as x FROM @TBooksNames 

بعض التسالي موفق انشاء الله .

هذه هي الطريقة التي أستخدمها، ولكنها تجعل الكود كبيراً للغاية؛ لذا فكرت باستخدام دالة معدة مسبقاً.
شكراً لك أخي العزيز
اذا كنت تريد استخدامه لعملية تعديل سجلات الجدول فهذا استعلام  :

PHP كود :
DECLARE @x int;
set @x= (Select ROW_NUMBER() OVER(ORDER BY (SELECT 1)))
DECLARE @
TBooksNames TABLE (id intChrCol nvarchar(255));
insert into @TBooksNames(id,ChrCol)values(@x,(CHAR(243)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(240)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(245)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(246)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(242)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(241)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(248)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(250)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,'ال')
DECLARE @
End int,@CharXT nvarchar(255);
set @End =(Select count(*) from @TBooksNames);
set @x=1;
WHILE @
< @End
begin
    set 
@CharXT=(select ChrCol from @TBooksNames where id=@x);
    
update @TBooksNames set ChrCol=REPLACE(ChrCol ,@CharXT ,'X'where id=@x;
    
set @+=1;
end;
Select from @TBooksNames

ملاحظة :
تستطيع استبدال الجدول الوهمي بجدول حقيقي بقاعدة البيانات و هذا يختصر الكود بشكل كبير و لا يبقى منه الا القليل مع اطيب امنياتي لك بالتوفيق و النجاح انشاء الله .
(02-11-20, 09:23 PM)asemshahen5 كتب : [ -> ]اذا كنت تريد استخدامه لعملية تعديل سجلات الجدول فهذا استعلام  :

PHP كود :
DECLARE @x int;
set @x= (Select ROW_NUMBER() OVER(ORDER BY (SELECT 1)))
DECLARE @
TBooksNames TABLE (id intChrCol nvarchar(255));
insert into @TBooksNames(id,ChrCol)values(@x,(CHAR(243)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(240)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(245)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(246)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(242)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(241)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(248)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(250)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,'ال')
DECLARE @
End int,@CharXT nvarchar(255);
set @End =(Select count(*) from @TBooksNames);
set @x=1;
WHILE @
< @End
begin
    set 
@CharXT=(select ChrCol from @TBooksNames where id=@x);
    
update @TBooksNames set ChrCol=REPLACE(ChrCol ,@CharXT ,'X'where id=@x;
    
set @+=1;
end;
Select from @TBooksNames

ملاحظة :
تستطيع استبدال الجدول الوهمي بجدول حقيقي بقاعدة البيانات و هذا يختصر الكود بشكل كبير و لا يبقى منه الا القليل مع اطيب امنياتي لك بالتوفيق و النجاح انشاء الله .

ألف شكر لك أخي العزيز.
أنا أريد عرض البيانات مرتبة مع تجاهل بعض العبارات، والعبارات سأضعها ضمن الدالة ReplaceString
وفي الحقيقة الغاية معرفة كيفية استخدام دالة ضمن جملة الاستعلام
هذا طلبك باذن الله :

PHP كود :
DECLARE @x int;
set @x= (Select ROW_NUMBER() OVER(ORDER BY (SELECT 1)))
DECLARE @
TBooksNames TABLE (id intChrCol nvarchar(255));
insert into @TBooksNames(id,ChrCol)values(@x,(CHAR(243)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(240)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(245)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(246)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(242)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(241)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(248)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(250)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,'ال')
DECLARE @
CharXT nvarchar(255);
set @CharXT  (CHAR(240)) + '|' + (CHAR(241)) + '|' + (CHAR(242)) +'|' + (CHAR(243)) +
                    (
CHAR(245)) + '|' + (CHAR(246)) + '|' + (CHAR(248)) +'|' + (CHAR(250));
select @CharXT;
select *
from    @TBooksNames
where   ChrCol like 
'%[^' + @CharXT ']%' escape '|' 



الكود حسب جدول بقاعدة البيانات :

PHP كود :
DECLARE @CharXT nvarchar(255);
set @CharXT  (CHAR(240)) + '|' + (CHAR(241)) + '|' + (CHAR(242)) +'|' + (CHAR(243)) +
                    (
CHAR(245)) + '|' + (CHAR(246)) + '|' + (CHAR(248)) +'|' + (CHAR(250));
select @CharXT;
select *
from    TBooksNames
where   ChrCol like 
'%[^' + @CharXT ']%' escape '|' 
(02-11-20, 10:30 PM)asemshahen5 كتب : [ -> ]هذا طلبك باذن الله :

PHP كود :
DECLARE @x int;
set @x= (Select ROW_NUMBER() OVER(ORDER BY (SELECT 1)))
DECLARE @
TBooksNames TABLE (id intChrCol nvarchar(255));
insert into @TBooksNames(id,ChrCol)values(@x,(CHAR(243)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(240)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(245)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(246)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(242)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(241)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(248)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,(CHAR(250)))
set @+= 1
insert into 
@TBooksNames(id,ChrCol)values(@x,'ال')
DECLARE @
CharXT nvarchar(255);
set @CharXT  (CHAR(240)) + '|' + (CHAR(241)) + '|' + (CHAR(242)) +'|' + (CHAR(243)) +
                    (
CHAR(245)) + '|' + (CHAR(246)) + '|' + (CHAR(248)) +'|' + (CHAR(250));
select @CharXT;
select *
from    @TBooksNames
where   ChrCol like 
'%[^' + @CharXT ']%' escape '|' 



الكود حسب جدول بقاعدة البيانات :

PHP كود :
DECLARE @CharXT nvarchar(255);
set @CharXT  (CHAR(240)) + '|' + (CHAR(241)) + '|' + (CHAR(242)) +'|' + (CHAR(243)) +
                    (
CHAR(245)) + '|' + (CHAR(246)) + '|' + (CHAR(248)) +'|' + (CHAR(250));
select @CharXT;
select *
from    TBooksNames
where   ChrCol like 
'%[^' + @CharXT ']%' escape '|' 

ظهر لي هذا الخطأ:
[attachment=25935]
جربته عندي و ده النتيجة :

[attachment=25939]

[attachment=25938]
(02-11-20, 07:51 PM)السندبااد كتب : [ -> ]
للأسف لم تنجح هذه الطريقة

جزاك الله خيراً

ولك بمثله

غريبة ، على العموم المبدأ واحد اذا كنت تريد ترتيب العناصر بناءا على دالة معرفة في مستوى الفيجوال بيسك يجب ان تقوم بترتيبهم في نفس المستوى ، اذ لا يمكن لل SQL معرفة الدوال المعرفة بمستوى اعلى منه 

لو تشاركني بالجزء الخاص بملىء الداتا تيبل لديك مثلا ربما نصل الى شيء وصدقني مرادك يتحقق ان شاء الله باستخدام LINQ
الصفحات : 1 2