?
Solved

What is the difference between CAST and CONVERT in SQL-Server 2000 ?

Posted on 2005-04-07
3
Medium Priority
?
584 Views
Last Modified: 2012-06-21

Hi,

Please let me know what is the difference between CAST and CONVERT in SQL-Server 2000 ?

Thanks,
Kishore
0
Comment
Question by:kishore_peddi
  • 2
3 Comments
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 13731487
CAST() can only change from one datatype to another.

CONVERT() can do editing/manipulation of the results.  For example, formatting a date in a particular way.

CAST() is ANSI-standard; CONVERT() is a MS extension.
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 1000 total points
ID: 13731516
So, if you are only changing from one datatype to another, you should use CAST() because it is more portable and much more likely to remain the same in the future:

DECLARE @d DECIMAL(5, 2)
SET @d = 123.45

-- *not* recommended ...
SELECT CONVERT(INT, @d)
-- ... use CAST() instead:
SELECT CAST(@d AS INT)


DECLARE @d DATE
SET @d = GETDATE()

-- want to show date as mm/dd/yyyy (only) -- must use CONVERT()
SELECT CONVERT(VARCHAR(10), @d, 101)
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 13732775
Hi kishore_peddi!

Actually, CAST and CONVERT provide similar functionality.

For your reference regarding this matter, visit this site : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp

Hope this makes sense.


Regards!
eNTRANCE2002 :-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question