October 18, 2005 at 7:18 am
I have three fields coming from an AS400 they are: year 4 digits, month 2 digits and day 2 digits,
I want this to be a small date when I bring it into SQL2000 is there a function that will let me do that?
Or how would I do that?
Thanks
Walter
October 19, 2005 at 2:40 am
Hi!!!!
If data is in XML format like as below then....
declare @idoc int
declare @doc varchar(1000)
set @doc ='
<ROOT YYYY="1996" MM="8" DD="11">
</ROOT>'
--Create an internal representation of the XML document.
exec sp_xml_preparedocument @idoc OUTPUT, @doc
-- SELECT stmt using OPENXML rowset provider
SELECT convert(varchar(10),cast((CONVERT(VARCHAR(10),(YYYY + '/'+ MM + '/' + DD))) as datetime),1) ORDERDATE INTO #Temp
FROM (
SELECT * FROM OPENXML (@idoc, '/ROOT',1)
WITH (YYYY varchar(4) ,
MM varchar(2) ,
DD varchar(2))
) P
SELECT * FROM #Temp
DROP TABLE #Temp
But just confirm that.....here field is inserting in MM/DD/YY format....
Regards,
Papillon
October 19, 2005 at 5:25 am
I get the data from the 400, I set up a job on sql2000 to qry the as400 via an odbc link and populate the sql2000 table with the data, I will try the SELECT convert(varchar(10),cast((CONVERT(VARCHAR(10),(YYYY + '/'+ MM + '/' + DD))) as datetime),1) and see if that works.
Thanks
Walter
October 31, 2005 at 10:30 pm
This works...
SELECT CAST(YYYY+MM+DD AS SMALLDATETIME)
The reason why it works is because yyyymmdd is one of the (ISO) recognized datetime formats... no need for the slashes or anything...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply