Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Can you please any one explain?


Can you please any one explain?

Author
Message
techmarimuthu
techmarimuthu
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 36
Difference between CAST and Convert functions in SQL SERVER??
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16447 Visits: 13202
Essentially they do the same, but you CONVERT has an optional third parameter you can use for formatting (mostly for conversions between dates and strings).

CAST is defined in the ANSI (or ISO or however you call it) SQL defination and is thus standard over all database platforms (or it should be), while CONVERT is more SQL Server specific.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Ed Wagner
Ed Wagner
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10256 Visits: 9571
I've seen many debates on CAST versus CONVERT and most center around performance. One comparison goes one way and the next one goes the other way. In the end, it depends on the specific test, but I've found them to pretty-much be a wash. Personally, I use CONVERT, but that just personal preference.


Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10707 Visits: 12008
Ed Wagner (8/9/2013)
I've seen many debates on CAST versus CONVERT and most center around performance. One comparison goes one way and the next one goes the other way. In the end, it depends on the specific test, but I've found them to pretty-much be a wash. Personally, I use CONVERT, but that just personal preference.

Personally, I'm lazy: in the cases where CAST is good enough, I use CAST because it means less typing. In the case where it isn't, I use CONVERT.

Tom

Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45080 Visits: 39912
techmarimuthu (8/9/2013)
Difference between CAST and Convert functions in SQL SERVER??


My recommendation would be to get into SSMS and press the {f1} key. There's a whole lot of good information on this very subject in Books Online.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16447 Visits: 13202
Jeff Moden (8/9/2013)
techmarimuthu (8/9/2013)
Difference between CAST and Convert functions in SQL SERVER??


My recommendation would be to get into SSMS and press the {f1} key. There's a whole lot of good information on this very subject in Books Online.


The page you get when you press F1 on cast or convert isn't exactly helpful, it's a stub referring you to another page :-D

(but I get the point, MSDN is a good resource for basic questions like this)



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Snigdha Vartak
Snigdha Vartak
Mr or Mrs. 500
Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)

Group: General Forum Members
Points: 526 Visits: 247
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.
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45080 Visits: 39912
Koen Verbeeck (8/11/2013)
Jeff Moden (8/9/2013)
techmarimuthu (8/9/2013)
Difference between CAST and Convert functions in SQL SERVER??


My recommendation would be to get into SSMS and press the {f1} key. There's a whole lot of good information on this very subject in Books Online.


The page you get when you press F1 on cast or convert isn't exactly helpful, it's a stub referring you to another page :-D

(but I get the point, MSDN is a good resource for basic questions like this)


What version are you using? I ask because I get a whole lot more than just a stub from BOL.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16447 Visits: 13202
Jeff Moden (8/13/2013)
Koen Verbeeck (8/11/2013)
Jeff Moden (8/9/2013)
techmarimuthu (8/9/2013)
Difference between CAST and Convert functions in SQL SERVER??


My recommendation would be to get into SSMS and press the {f1} key. There's a whole lot of good information on this very subject in Books Online.


The page you get when you press F1 on cast or convert isn't exactly helpful, it's a stub referring you to another page :-D

(but I get the point, MSDN is a good resource for basic questions like this)


What version are you using? I ask because I get a whole lot more than just a stub from BOL.


Ah, it seems to be solved in SQL Server 2012.
I'm still using SQL Server 2008R2 at the client.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
techmarimuthu
techmarimuthu
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 36
i m using SQL server 2005
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search