August 4, 2008 at 12:52 pm
What is the main difference between cast and convert?
In datetime and another datatypes why we can chose particular cast or convert?
August 4, 2008 at 1:04 pm
They do the same thing, just a slightly different syntax. I prefer using Convert. I believe CAST is more widely implemented by other database platforms.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
August 4, 2008 at 1:48 pm
Jack Corbett (8/4/2008)
They do the same thing, just a slightly different syntax. I prefer using Convert. I believe CAST is more widely implemented by other database platforms.
Although you can CAST a char/varchar to a datetime in some cases (as long as the format of the string matches the dateformat), you are better off using CONVERT so you can specify the format yourself.
Also, trying to CAST a datetime to a char will also present problems that can only be overcome using CONVERT.
So, yes - they can be interchanged for the most part, but there are a few things where using CONVERT is better.
BTW - CAST is part of the ANSI standard whereas CONVERT is not.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
August 4, 2008 at 1:49 pm
I think one has a few more options, but they work the same.
August 4, 2008 at 2:14 pm
Thank you Williams for your satisfaction reply
bye
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply