Solved

SQL Convert

Posted on 2015-02-24
4
207 Views
Last Modified: 2015-02-24
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
Comment
Question by:HLRosenberger
  • 2
  • 2
4 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
Comment Utility
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
 
LVL 1

Author Comment

by:HLRosenberger
Comment Utility
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
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
Comment Utility
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
 
LVL 1

Author Closing Comment

by:HLRosenberger
Comment Utility
Thanks!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now