Solved

SQL Convert

Posted on 2015-02-24
4
214 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
ID: 40628298
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
ID: 40628311
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
ID: 40628331
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
ID: 40628388
Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

830 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