January 17, 2012 at 9:52 am
select replace('1 - Apr',' ','') dt
into #test
select dt --how do i convert this varchar to a datetime
from #test
January 17, 2012 at 10:02 am
What year?
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
January 17, 2012 at 10:13 am
sorry. it's coming in a different column
select replace('1 - Apr',' ','') dt, 2010 [year]
into #test
select dt,year --how do i convert this varchar to a datetime
from #test
January 17, 2012 at 10:18 am
captcooldaddy (1/17/2012)
sorry. it's coming in a different columnselect replace('1 - Apr',' ','') dt, 2010 [year]
into #test
select dt,year --how do i convert this varchar to a datetime
from #test
Can you set up a few rows of sample data exactly as it is in the source table, making sure the datatypes are the same? The link in my sig will show you how to do this.
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
January 17, 2012 at 10:20 am
here's my first guess; there's a lot of flexibility in ISDATE and convert, you might get dates that are out of range.
;With mySampleData
AS
(
select '1 - Apr' As dt, 2010 AS [year] UNION ALL
SELECT 'august ',2011
)
select mySampleData.*,
CASE
WHEN ISDATE(dt + ' ' + CONVERT(varchar,[year])) = 1
THEN CONVERT(datetime,dt + ' ' + CONVERT(varchar,[year]))
ELSE NULL
END
FROM mySampleData
Lowell
January 17, 2012 at 10:31 am
thanks guys. I'll provide more infor in an hour or so. just got slammed.
January 17, 2012 at 12:00 pm
actually never mind. That worked "SSCrazy Eights". Thank you guys...again...
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply