Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi all, I have a table with column c1 varcharI have both text data and datetime data in that column.Now how can i truncate time from date without affecting other fielsfor egc1--------ad'01/01/1990 23:09:56'rtfrom the above table i need the output likec1---ad'01/01/1990'rthow can i acheive this?
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-08-19 : 05:17:10
[code]SELECT CASE WHEN ISDATE(c1)=1AND LEN(c1) >10 THEN LEFT(c1,CHARINDEX(' ',c1)-1)ELSE c1 ENDFROm YourTable[/code]
PeterNeo
Constraint Violating Yak Guru
357 Posts
Posted - 2008-08-19 : 05:29:32
try this
declare @t table ( c1 varchar(100))insert into @tselect 'a' union allselect 'd' union allselect '01/01/1990 23:09:56' union allselect 'r' union allselect 't'update @tset c1 = convert(varchar(10), dateadd(day, datediff(day, 0, c1), 0), 101)where isdate(c1) = 1selecT * from @t
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2008-08-19 : 06:01:44
quote:Originally posted by PeterNeo try this
declare @t table ( c1 varchar(100))insert into @tselect 'a' union allselect 'd' union allselect '01/01/1990 23:09:56' union allselect 'r' union allselect 't'update @tset c1 = convert(varchar(10), dateadd(day, datediff(day, 0, c1), 0), 101)where isdate(c1) = 1selecT * from @t