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)
 Cast/Substring Func not working

Author  Topic 

Trudye
Posting Yak Master

169 Posts

Posted - 2009-10-17 : 15:31:23
Hi Guys, having a little trouble with the following func.:
select CAST(SUBSTRING(CEFDT, 5, 2) AS varchar) as Eff_Date
FROM DBO.DtTbl


CEFDT is a date with a format of yyyymmdd that I need to convert to mmddyyyy. The Right/Left functions are working fine this one is giving me grief. I am receiving the following msg:
Argument data type numeric is invalid for argument 1 of substring function.

Any idea how I can fix this one?
Thanx much

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-10-17 : 15:56:11
What data type is CEFDT? Is it varchar, char, or int?

If LEFT/RIGHT are working fine for you, then why don't you use those?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

dsdeming

479 Posts

Posted - 2009-10-18 : 10:52:46
How about this:

select SUBSTRING(CONVERT(char(8), CEFDT, 112), 5, 2) as Eff_Date
FROM DBO.DtTbl


Dennis
Go to Top of Page
   

- Advertisement -