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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Only date from datetime and "CONCAT(+)"

Author  Topic 

phredator
Starting Member

2 Posts

Posted - 2008-06-13 : 07:31:55
Hi there i have this:
CAST(CAST(FLOOR(CAST(CREATED AS FLOAT))AS DATETIME) AS varchar)+' '+CAST(SUBJECT as varchar)AS DESCRIPTION

And it returns data like this "Jun 13 2008 02:00AM My description"
I just want to get the "2008-06-13 My description"

I have the
CAST(FLOOR(CAST(CREATED AS FLOAT))AS DATETIME)
in another sql-question and that works it returns only "2008-06-13"

I think you see what im after, any ideas ?

Regards
Fredrik

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-13 : 07:33:50
SELECT CONVERT(CHAR(10), Created, 120) + ' ' + Subject AS Description
FROM Table1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-13 : 07:35:51
may be this:-

CONVERT(varchar(11),CAST(FLOOR(CAST(CREATED AS FLOAT))AS DATETIME),121)+' '+CAST(SUBJECT as varchar(length)AS DESCRIPTION


replace length with length of your SUBJECT column. ALways make it a point to specify length while casting to varchar
Go to Top of Page

phredator
Starting Member

2 Posts

Posted - 2008-06-13 : 07:41:32
quote:
Originally posted by Peso

SELECT CONVERT(CHAR(10), Created, 120) + ' ' + Subject AS Description
FROM Table1



Thanks wery much fot your extremly fast answer, it worked lika a charm, but to understand what im doing :) What does the code CONVERT(CHAR(10), Created, 120) really do ? And what is the number 120, where can i read more about this ?

Thanks alot

Regards
Fredrik
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-13 : 07:44:51
Books Online, the SQL Server help file.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

bjoerns
Posting Yak Master

154 Posts

Posted - 2008-06-16 : 06:28:23
I also like this one:

http://databases.aspfaq.com/database/what-are-the-valid-styles-for-converting-datetime-to-string.html

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-16 : 06:53:19
Also available here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80563



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -