دالة SQL Server CONVERT ()
مثال
تحويل تعبير إلى int:
SELECT CONVERT(int, 25.65);
التعريف والاستخدام
تحول الدالة CONVERT () قيمة (من أي نوع) إلى نوع بيانات محدد.
نصيحة: انظر أيضًا إلى وظيفة CAST () .
بناء الجملة
CONVERT(data_type(length), expression, style)
قيمه المعامل
Value | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data_type | Required. The datatype to convert expression to. Can be one of the following: bigint, int, smallint, tinyint, bit, decimal, numeric, money, smallmoney, float, real, datetime, smalldatetime, char, varchar, text, nchar, nvarchar, ntext, binary, varbinary, or image | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(length) | Optional. The length of the resulting data type (for char, varchar, nchar, nvarchar, binary and varbinary) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expression | Required. The value to convert to another data type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
style | Optional. The format used to convert between data types, such as a date
or string format. Can be one of the following values:
Converting datetime to character:
|
تفاصيل تقنية
يعمل في: | SQL Server (بدءًا من 2008) ، قاعدة بيانات Azure SQL ، مستودع بيانات Azure SQL ، مستودع البيانات المتوازي |
---|
مزيد من الأمثلة
مثال
تحويل تعبير من نوع بيانات إلى آخر (varchar):
SELECT CONVERT(varchar, 25.65);
مثال
تحويل تعبير من نوع بيانات إلى آخر (تاريخ / وقت):
SELECT CONVERT(datetime, '2017-08-25');
مثال
تحويل تعبير من نوع بيانات إلى آخر (varchar):
SELECT CONVERT(varchar,
'2017-08-25', 101);