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
 General SQL Server Forums
 New to SQL Server Programming
 cONVERTING FLOAT TO VARCHAR DATA TYPE

Author  Topic 

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2009-10-23 : 02:46:13
Hi,

I have a field name 'Datewritten'as float in the client table .
The date written field will display datetime but it is declared in float format and cant be alterd.

Now i need to display it in the form of varchar

The original Display is
it shows like this '20090224.0'

I want it to display as 'Feb 24 2009' can anyone help me on this.Very urgent

susan

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-10-23 : 03:06:03
Try this....

declare @var float
set @var=20090224.0

select left(convert(varchar,cast(cast(cast(@var as int) as varchar) as datetime),100),11)



Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-23 : 03:55:56
quote:
Originally posted by senthil_nagore

Try this....

declare @var float
set @var=20090224.0

select left(convert(varchar,cast(cast(cast(@var as int) as varchar) as datetime),100),11)



Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/



Always specify the length when converting to varchar
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -