?
Solved

what's the best way to concatenate this date?

Posted on 2005-03-20
4
Medium Priority
?
256 Views
Last Modified: 2006-11-17
Hi.  I'm looking to get a datetime concatenated value from my table -- this is probably quite easy, but I'm not getting what I want.

this gives me this:  20050320
select convert(varchar(12),getdate(), 112)

what's the right way to return this:  20050320.14:23:53.140

0
Comment
Question by:RLLewis
[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
4 Comments
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
ID: 13587215
This should get you closer to your purpose...
select (convert(varchar(12),getdate(), 112) + '.' + right (cast(getdate() as varchar(50)), len(cast(getdate() as varchar(50)) - 11)  
0
 
LVL 1

Author Comment

by:RLLewis
ID: 13587247
nope - syntactically incorrect.  i added the missing paren after the first getdate(), 112), but now I'm getting this error:
Syntax error converting the varchar value 'Mar 20 2005  2:49PM' to a column of data type int.

select (convert(varchar(12),getdate(), 112)) + '.' + right (cast(getdate() as varchar(50)), len(cast(getdate() as varchar(50)) - 11))

this gets me this:  20050320. 2:48PM
select (convert(varchar(12),getdate(), 112)) + '.' + RIGHT(CONVERT(VARCHAR(30), getdate(), 100), 7)

but I don't want the time in that format.  any ideas?
0
 
LVL 17

Accepted Solution

by:
BillAn1 earned 200 total points
ID: 13587338
try this one :

select replace(replace(convert(varchar(23), getdate(), 121),'-',''),' ','.')
0
 
LVL 1

Author Comment

by:RLLewis
ID: 13587350
perfect.  thank you
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

777 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