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.
| Author |
Topic |
|
OON
Starting Member
22 Posts |
Posted - 2010-11-02 : 16:16:54
|
| Hello,Im trying to convert a datatype to the Date format 101 using the following;CONVERT(CHAR(10),INDV_DOB,101)AS BIRTH_DATEThe original data in INDV_DOB are as follows:(Sample Data)INDV_DOB2002050220010723 20010723 20030705 19990227 19990227 20000805 However, after using the convert function the data returned is still in the same format as the sample provided above instead of the 101 format which should be something like:11/23/1998.Thanks for your help |
|
|
OON
Starting Member
22 Posts |
Posted - 2010-11-02 : 16:22:02
|
| If it helps, here;s the actual query im usingSELECT F.HRN AS 'MED_REC',F.NDC_NO,F.DISP_DT,F.QTY,F.DAYS_SUPPLY,CONVERT(CHAR(10),INDV_DOB,101)AS BIRTH_DATE,PROV,PHYS_NAME,NDC_SPECIALTY,DEA_NO --INTO ADHD_CLAIMSFROM RX.PRESC_CLAIMS FINNER JOIN c438155.modified_ADD_A AL ON F.NDC_NO=NDC_CDINNER JOIN CM.MemberDemogHRNLookup LU ON F.HRN=LU.MemberMRNINNER JOIN CM.KDINDV1V K ON LU.MemberHRN=K.INDV_HRNLEFT OUTER JOIN RX.NDC_PHYS MD ON F.PRESCRIBER_NAME=MD.DEA_NOWHERE (F.DISP_DT BETWEEN '2010-10-01' AND '2010-11-01' ) AND(K.INDV_DOB BETWEEN 19981101 AND 20051001) |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2010-11-02 : 16:23:24
|
one way isSELECT CONVERT(CHAR(10),CAST('20020502' AS DATETIME),101)AS BIRTH_DATE05/02/2002If you don't have the passion to help people, you have no passion |
 |
|
|
OON
Starting Member
22 Posts |
Posted - 2010-11-02 : 16:27:41
|
| Hello,i did this CONVERT(CHAR(10),CAST(K.INDV_DOB AS DATETIME),101)AS BIRTH_DATE,using the column in the table and i get the following error:Msg 8115, Level 16, State 2, Line 1Arithmetic overflow error converting expression to data type datetime.Could this be issue with the column format?Thanks |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2010-11-02 : 17:46:00
|
1. is your datatype for INDV_DOB be int2. you might have dirty data in INDV_DOB field. Could there be NULLs also? basically you have a bad design here with INDV_DOB. Anyways try the following SELECT HowAreYouDate = CASE WHEN ISDATE(INDV_DOB ) = 1 THEN 'I am fine and you' ELSE 'I am not a date you sucka' END, *from CM.KDINDV1V If you don't have the passion to help people, you have no passion |
 |
|
|
|
|
|
|
|