| Author |
Topic |
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2012-08-28 : 10:16:33
|
| Error msg:Msg 242, Level 16, State 3, Line 1The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.Here is my query below:----------------------------select distinct [Last Name],[First Name],[Registration Date],[Year and Quarter],left(integratedPlacement,5) nhPlxQtr,[nhd],[WAGES],[integratedPlacement],right(integratedPlacement,2) placementtype,nhdEmp = case when nhd is not null and wages is nullthen nh.emp_nmeelse 'x'end,nhd_emp_addr_ln1 = case when nhd is not null and wages is nullthen nh.emp_addr_ln1else 'x'end,nhd_emp_cty = case when nhd is not null and wages is nullthen nh.emp_ctyelse 'x'end,nhd_emp_st = case when nhd is not null and wages is nullthen nh.emp_stelse 'x'end,emp_zip = case when nhd is not null and wages is nullthen nh.emp_zipelse 'x'end,[company],[Address],[City],[State],[Zip Code],[Zip + 4],[PHONE],[Industry Type],[OneStop],[dhmOffice]from (select distinct xx.[Last Name],xx.[First Name],xx.[Registration Date],xx.[Year and Quarter],convert(smalldatetime, convert(varchar(10),nh.nh_dte, 112)) nhd,xx.[WAGES],integratedPlacement =case when xx.[Year and Quarter] is not nullthen xx.[Year and Quarter] + 'ui'when 1=1and xx.[Year and Quarter] is nulland nh.ssn = xx.ssn and convert(smalldatetime, convert(varchar(10),nh.nh_dte, 112)) >= xx.[Registration Date]then convert(varchar,datepart(year,nh.nh_dte)) + convert(varchar,datepart(quarter,nh.nh_dte)) + 'nh'when xx.[Year and Quarter] is nulland nh.ssn != xx.ssn then Nullwhen xx.wages is nulland nh.ssn = xx.ssnand convert(smalldatetime, convert(varchar(10),nh.nh_dte, 112)) < xx.[Registration Date]then Nullelse 'N'end,xx.[company],xx.[Address],xx.[City],xx.[State],xx.[Zip Code],xx.[Zip + 4],xx.[PHONE],xx.[Industry Type],xx.[OneStop],xx.[dhmOffice],xx.ssnfrom(select distinctrgn [rgn],x.uSSN ssn,convert(varchar,appid) [appid],convert(varchar,usn) [usn],lname [Last Name],fname [First Name],regdte [Registration Date],convert(varchar,yrqtr) [Year and Quarter],convert(money,wages) [WAGES],primadd1 [company],primadd5 [Address],primcity [City],primstate [State],primzip [Zip Code],primzip4 [Zip + 4],phone [PHONE],indname [Industry Type],ofx_ofx [OneStop],dhmOfficefrom(select de.* ,ui.*-------------- ,EMPDuringPartx =casewhen (de.hssn = ui.ssn and (convert(int,ui.yrqtr) - convert(int,de.regYQi))= 1) or (de.hssn = ui.ssn and (convert(int,ui.yrqtr) - convert(int,de.regYQi))= 2) or (de.hssn = ui.ssn and (convert(int,ui.yrqtr) - convert(int,de.regYQi))= 3)or (de.hssn = ui.ssn and (convert(int,ui.yrqtr) - convert(int,de.regYQi))= 4)then 'Y'else 'N'end----------,EMPQ1aftExitYN =casewhen (de.hssn = ui.ssn and (convert(int,ui.yrqtr) - convert(int,de.xdtYQi))= 1) then 'Y'else 'N'endfrom ospr_workarea.dbo.dhmEFM deleft outer join ospr_workarea.dbo.roger_ui uion (de.hssn = ui.ssn and (ui.YRQTR >= de.regYQ or (ui.YRQTR >= de.appYQ )) )where 1=1) xwhere 1=1and xdtYQ is not null ---exiters only) xxleft outer join ospr_workarea.dbo.mmr_dor_new_hire nhon (nh.ssn = xx.ssn and xx.[Year and Quarter] is nulland left(nh.nh_dte,2) = '20'and convert(smalldatetime, convert(varchar(10),nh.nh_dte, 112)) >= xx.[Registration Date])) xx1left outer join ospr_workarea.dbo.mmr_dor_new_hire nhon (nh.ssn = xx1.ssn and left(nh.nh_dte,2) = '20'and convert(smalldatetime, convert(varchar(10),nh.nh_dte, 112)) >= xx1.[Registration Date] and xx1.nhd is not null)Roger DeFour |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-08-28 : 10:18:31
|
the error must be coming from "convert(smalldatetime, convert(varchar(10),nh.nh_dte, 112))"what is the data type for column nh.nh_dte ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2012-08-28 : 10:42:12
|
| The data type is varchar(8),nullRoger DeFour |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-08-28 : 10:50:17
|
Examine the data in each of the columns that you are converting to smalldatetime to see if they are valid dates. For example, to examine nh_dte column in the table ospr_workarea.dbo.mmr_dor_new_hire, use this query: SELECT *FROM ospr_workarea.dbo.mmr_dor_new_hireWHERE ISDATE(nh_dte) = 0 |
 |
|
|
|
|
|