Skip to main content

الجزء ال15: coalesce function

الجزء ال15: coalesce function

في الجزء ال14 تعلمنا كيفية استبدال قيمة باطلة NULL بقيمة تحددها, من ضمن تلك الطرق هي بأستخدام دالة تسمى بCOALESCE , حيث عمل هذه الدالة لا يقتصر على استبدال القيمة الباطلة NULL الى قيمة اخرى فقط , وانما يعمل على استرجاع اول قيمة غير باطلة من اكثر من حقل محدد داخل هذه الدالة لنرى ذلك في مثال:
ID
FirstName
MiddleName
LastName
1
صفاء
NULL
ناصر
2
حسين
علاء
NULL
3
علي
NULL
ناصر
4
NULL
سارة
NULL
5
NULL
محمد
جميلة
6
مؤمن
NULL
NULL

نريد استرجاع قيم الجدول اعلاه كالأتي:
ID
Name
1
صفاء
2
حسين
3
علي
4
سارة
5
محمد
6
مؤمن

اول شيء لتطبيق الدرس يتوجب أنشاء الجدول اعلاه:

USE [test]
GO
CREATE TABLE tblEmployeesFullName
(
ID INT NOT NULL PRIMARY KEY IDENTITY(1,1),
FirstName NVARCHAR(20) ,
MiddleName NVARCHAR(20),
LastName NVARCHAR(20)
)


الجواب
بأستخدام دالة الCOALESCE يمكن استخراج اول قيمة غير ملغية NULL من عدة حقول كالأتي:

USE [test]
GO
SELECT ID,
COALESCE(FirstName,MiddleName,LastName) as Name
FROM tblEmployeesFullName



حددنا في دالة الCOALESCE ثلاث حقول, حيث ستعمل هذه الدالة على فحص اول قيمة في الحقل الأول اذا كانت باطلة NULL ستهملها وستنتقل للحقل الثاني اذا كانت باطلة NULL ستهملها وستنتقل للحقل الثالث, فأذا كان الأسم الأخير في الحقل الثالث لا يحتوي على قيمة باطلة ستسترجع هذه القيمة وستنتقل الدالة على سجل جديد ونفس العملية تتكرر.

Comments

Popular posts from this blog

How To Play .srt Subtitles File in Windows Media Player

How To Play .srt Subtitles File in Windows Media Player links: https://sourceforge.net/projects/wmpsub/ wmp,.srt Subtitles File in Windows Media Player,How To Play .srt Subtitles File in Windows Media Player,How To,Safaa Al-Hayali,saf3al2a,srt subtitle in WMP,Windows,Windows Media Player,media,.ass,local subtitles

How to fix the disk is write protected

in this video tutorial, I'll show you how to remove/solve/fix the disk is write protected from USB flash drive. To download the necessary 2 files: Download >  SAFAA_ALHAYALI.IMG  - 1.18 MB Download >  Win32DiskImager-0.9.5-install.exe - 11.7 MB write protection,remove write protection,write protected,How to fix the disk is write protected,how to solve the disk is write protected,how to remove the disk is write protected,USB write protected,fix USB write protected,fix HDD write protected,how to,windows,USB flash drive ERROR,fix USB flash drive write protected,USB flash drive write protected

Virtual Box : How to Increase Disk Size - Windows

How to increase disk size or disk storage in oracle virtual box the command you have to use: vboxmanage.exe modifymedium "[YourPathToVdiFileOfYourVirtualMachine]" --resize [NUMBER] virtual,box,vbox,oracle,partition,size,disk,increase,resize,windows,10,microsoft,vdi,vboxmanage,configuration,Safaa AL-Hayali,saf3al2a,Oracle,VirtualBox,How to,windows 10