Solved

SQL Convert

Posted on 2015-02-24
4
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

738 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