ورود

View Full Version : توضیح در مورد دستور castوروش استفاده از آن و فرقش باconvert چیست؟



پناه پناهی
جمعه 26 آبان 1391, 17:04 عصر
توضیح در مورد دستور castوروش استفاده از آن و فرقش باconvert چیست؟

baktash.n81@gmail.com
شنبه 27 آبان 1391, 08:11 صبح
یه نگاهی به این (http://beyondrelational.com/modules/2/blogs/70/posts/10903/sql-server-difference-between-tsql-functions-cast-and-convert.aspx)بندازین ...

tooraj_azizi_1035
دوشنبه 29 آبان 1391, 09:31 صبح
شرمنده وقت ترجمه نداشتم:

SQL Server programmers can choose between two functions in SQL Server 7 and 2000 for converting expressions from one type to another. In many cases there will be a need within a stored procedure or other routine to convert data from, say, a datetime type to a varchar type; CONVERT and CAST are used for such things.
Because SQL Server provides both functions, there may be some confusion about which is best to use and under what circumstances. CONVERT is specific to SQL Server, and allows for a greater breadth of flexibility when converting between date and time values, fractional numbers, and monetary signifiers.
CAST is the more ANSI-standard of the two functions, meaning that while it's more portable (i.e., a function that uses CAST can be used in other database applications more or less as-is), it's also less powerful. CAST is also required when converting between decimal and numeric values to preserve the number of decimal places in the original expression. For those reasons, it's best to use CAST first, unless there is some specific thing that only CONVERT can provide in the work you're doing.
CAST and CONVERT can also be used in conjunction with each other to achieve certain effects. For instance, a typical way to produce a char variable with the current date would be to use:
SELECT CONVERT(CHAR(10), CURRENT_TIMESTAMP,

mahdi_7610
چهارشنبه 01 آذر 1391, 00:47 صبح
تفاوت Cast و Convert

Cast زمانی استفاده می شود که دو متغیر مبدا و مقصد از یک خانواده باشند اما Convert حتی برای تبدیل تایپ هایی که از یک نوع نیز نمی باشند استفاده می شود