?
Solved

SQL Convert

Posted on 2015-02-24
4
Medium Priority
?
218 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 2000 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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 SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

741 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