Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Johnph
Posting Yak Master
103 Posts |
Posted - 2013-05-06 : 17:02:29
|
[code]Convert(varchar(500),[DATE])FROM TABLE[/code]My datetime fields looks like this:2013-05-02 17:41:35.790and I want the output as: 2013-05-02 17:41:35.790but in varchar. My query is giving me May 5 2013.Sorry if this has been asked before, but I could not find it. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-05-06 : 17:04:21
|
Use a specific style - for example CONVERT(varchar(32),[DATE],120) All the styles are listed here. http://msdn.microsoft.com/en-us/library/ms187928.aspx |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-07 : 01:02:13
|
I dont understand why you want to change datatype if the value is already in the format you desire. In any case formatting should be done at front end wherever possible. Doing this at sql requires unnecessary convert/cast operations and would evenmake any further manipulations using these values difficult.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Johnph
Posting Yak Master
103 Posts |
Posted - 2013-05-07 : 10:32:25
|
Thanks to both.Visakh - I want to convert everything into a varchar so that I can concatenate a large string with multiple columns. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-08 : 00:19:02
|
quote: Originally posted by Johnph Thanks to both.Visakh - I want to convert everything into a varchar so that I can concatenate a large string with multiple columns.
Whats the purpose of doing this?Is it for display or is it for sending them as delimited list to some other function? If latter, there are much better approaches like XML------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Johnph
Posting Yak Master
103 Posts |
Posted - 2013-05-08 : 16:09:04
|
Yup, a delimited text file which I can use later for a bulk insert. Visakh, can you send me maybe a beginner's guide to XML with SQL server? |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
|
|
|
|