Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2012-04-05 : 10:08:14
|
| I am going over a SQL script written by another person trying to figure out what it does. In doing so I have noticed they seem to swap between using cast(UserNID AS varchar(16)) and convert(varchare(16),UserNID) all over the place. I read over the MSDN page on CAST and CONVERT and did not see any real difference (the page even gives examples using both that generate the same output). So what is the difference and why might have this person been going back and forth?-- If I get used to envying others...Those things about my self I pride will slowly fade away.-Stellvia |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-05 : 10:22:04
|
| they have one difference. Using CONVERT you can specify a style value based on which you can specify what format you want date values to be displayed/ interpreted.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
|
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2012-04-05 : 10:26:26
|
quote: Originally posted by visakh16 they have one difference. Using CONVERT you can specify a style value based on which you can specify what format you want date values to be displayed/ interpreted.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
So since UserNID is an INT and it is only ever being converted over to varchar there will be no functionallity difference? Forgot to metion this is on SQL 2008 R1. If there is no difference I should probibily convert to CAST for consistancy then?-- If I get used to envying others...Those things about my self I pride will slowly fade away.-Stellvia |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-05 : 11:43:20
|
quote: Originally posted by Eagle_f90
quote: Originally posted by visakh16 they have one difference. Using CONVERT you can specify a style value based on which you can specify what format you want date values to be displayed/ interpreted.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
So since UserNID is an INT and it is only ever being converted over to varchar there will be no functionallity difference? Forgot to metion this is on SQL 2008 R1. If there is no difference I should probibily convert to CAST for consistancy then?-- If I get used to envying others...Those things about my self I pride will slowly fade away.-Stellvia
if its int CAST/CONVERT is equivalent------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2012-04-05 : 13:51:33
|
| Thanks-- If I get used to envying others...Those things about my self I pride will slowly fade away.-Stellvia |
 |
|
|
|
|
|