Author |
Topic |
Pace
Constraint Violating Yak Guru
264 Posts |
Posted - 2006-12-18 : 05:12:28
|
Hi All, Please can someone explain to me what the difference is between CAST and CONVERT. For example if you run the following;SELECT CONVERT(nvarchar(30), GETDATE())AS UsingConvert, CAST(GETDATE() AS nvarchar(30)) AS UsingCastGO Gives you the same result set."Impossible is Nothing"  |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-12-18 : 05:19:48
|
CAST and CONVERT basically provide similar functionality, but CONVERT gives you more control over the formatting of the value by providing Style parameter.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
Kristen
Test
22859 Posts |
Posted - 2006-12-18 : 05:37:11
|
I provide to think of CONVERT as a function, and use it as such. The syntax of CAST suits my programming style less.Kristen |
 |
|
Pace
Constraint Violating Yak Guru
264 Posts |
Posted - 2006-12-18 : 05:41:06
|
Thank you "Impossible is Nothing" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-18 : 07:25:47
|
CONVERT is more powerful when you want to convert the DATE into different formats.But if you use front end application, you should format the DATE thereMadhivananFailing to plan is Planning to fail |
 |
|
Pace
Constraint Violating Yak Guru
264 Posts |
Posted - 2006-12-18 : 11:58:38
|
Really? I tend to SP absolutely all INSERT UPDATE DELETE statements... I appreciate putting the Client back into Client / Server, I tend to only use the client machine for calculating the data that gets sent from the server."Impossible is Nothing" |
 |
|
Kristen
Test
22859 Posts |
Posted - 2006-12-18 : 12:38:36
|
"I tend to only use the client machine for calculating the data that gets sent from the server"So you mean that you would "style" a Date in the Server, rather than the Client?The reason for not doing this is so that you transfer a "date object" from Server to Client, and that Client doesn't have to parse it [possibly ambiguously] and can do "stuff" with it - like sort into chronological order; compare two dates; format appropriately for the Locale the client is in, etc.(But I reckon you know that, so maybe I've got the wrong end of what you meant??)Kristen |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-19 : 22:53:06
|
quote: Originally posted by Pace Hi All, Please can someone explain to me what the difference is between CAST and CONVERT. For example if you run the following;SELECT CONVERT(nvarchar(30), GETDATE())AS UsingConvert, CAST(GETDATE() AS nvarchar(30)) AS UsingCastGO Gives you the same result set."Impossible is Nothing" 
Why do you need nvarchar anyway?MadhivananFailing to plan is Planning to fail |
 |
|
Kristen
Test
22859 Posts |
Posted - 2006-12-20 : 10:43:43
|
"Why do you need nvarchar anyway?"To save some CPU cycles on the Client? |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-20 : 10:52:01
|
quote: Originally posted by Kristen "Why do you need nvarchar anyway?"To save some CPU cycles on the Client? 
Kristen, you have high sense of Humour MadhivananFailing to plan is Planning to fail |
 |
|
Kristen
Test
22859 Posts |
Posted - 2006-12-20 : 10:57:45
|
I thought you'd like that one!! |
 |
|
X002548
Not Just a Number
15586 Posts |
|
|