• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

SQL Convert

I'm unclear on what the third arg to Convert does.   it a astyle, correct?  What, if anything would be the difference in these two statements below;  What's the 0 style mean?

(CONVERT([varchar](75),case when [middle_name] IS NULL then ([last_name]+', ')+[first_name] else ((([last_name]+', ')+[first_name])+' ')+[middle_name] end))

(CONVERT([varchar](75),case when [middle_name] IS NULL then ([last_name]+', ')+[first_name] else ((([last_name]+', ')+[first_name])+' ')+[middle_name] end, 0))
0
HLRosenberger
Asked:
HLRosenberger
  • 2
  • 2
1 Solution
 
Paul JacksonCommented:
The 3rd argument is a style argument used for formatting dates.
There would be no difference between the above statements as the lack of a style argument is the same as specifying a 0.

See the following link for more info :

http://www.w3schools.com/sql/func_convert.asp
0
 
HLRosenbergerAuthor Commented:
ok, thanks.  I saw a similar type article - however, where does it say that a 0 style is the same not specifying any style?   And style is only for dates?
0
 
Paul JacksonCommented:
In the table of possible values O or 100 is the default style as shown in the Standard column so will be used if you do not specify a style.

Convert can be used to convert any datatype to another however the style is only used to format the output if the output datatype is a date/time.
So actually in your second statement above the style argument would be disregarded as the output is not a date/time.

It is shown that the 3rd argument is only used for dates in the description of the function at the top of the page and in the description of the arguments a little bit further down.
0
 
HLRosenbergerAuthor Commented:
Thanks!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now