Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing criteria causes error?

Status
Not open for further replies.

pluto1415

MIS
Apr 28, 2009
78
US
I've got the following SQL statement (not written by me, just inherited) that works correctly. Unfortunately, now I need to remove the requirement that i.attr3209='Active' as we'd like to see all, not just the active ones. When I comment out the 2nd occurrence of i.attr3209='Active', SQL throws an error that says Conversion failed when converting datetime from character string. (MS SQL Server, Error: 241). I don't understand why it throws this when I remove a line that has nothing to do with the datetime fields. Also, it doesn't throw the error when I comment out the first occurrence, just the second...

Code:
DECLARE @intFlag INT
SET @intFlag = 1
truncate table hsi.rmDeutscheLAT

WHILE (@intFlag <=2000)
BEGIN
insert into hsi.rmDeutscheLAT
select distinct top 1
cc.mk3611 'memoid',/*Used to gather Health Notes*/
p.attr3176 'Case ID',
f.attr3106'Funder',
sf.attr3133'SubFund',
i.attr3226'Do Not Call',/*Used to update the reporting table*/
cc.attr3618'LastContact',
i.attr3207'Insured Last Name',
i.attr3206'Insured First Name',
i.attr3210 as 'SSN',
'Complete' as 'Tracking Status',
cc.attr3614'Method of Contact',
convert(varchar,cc.attr3618,106)'Date of Last Contact',
cc.attr3618'LastContactDate',/*Used to Sort - Date of Last Contact is not a date field*/
DATENAME(month,i.attr3225)'Date of Next Contact',
cc.attr3616'Respondent',
cc.attr3619'Contact Information',
cc.attr3610'Significant Changes in Health',
'' as'Health Change Comments',
'Yes'as'SS Sweep Completed',
cc.attr3605'Address Confirmation',
i.attr3209'Status'

from hsi.rmobjectinstance1184 i,hsi.rmobjectinstance1183 p,hsi.rmobjectinstance1204 cc, hsi.rmobjectinstance1180 sf, hsi.rmobjectinstance1178 f

where sf.fk3144=f.objectid and p.fk3186=sf.objectid and p.fk3183=i.objectid and cc.fk3608=i.objectid
and f.activestatus=0 and sf.activestatus=0 and p.activestatus=0 and i.activestatus=0 and cc.activestatus=0 
and f.attr3106='Deutsche Bank' and sf.attr3133='DB - LAT'
and i.attr3210/*SSN*/ not in (select SSN from hsi.rmDeutscheLAT)/*Allows only one line per Insured*/
[COLOR=red]--and i.attr3209='Active'[/color]
order by i.attr3210,LastContactDate desc /*Makes the top result for each Insured the proper one*/
SET @intFlag = @intFlag + 1
END
--GO
--Inserts Insureds/Policies without Continued Contacts
insert into hsi.rmDeutscheLAT
select 
'',p.attr3176 'Case ID',f.attr3106'Funder',sf.attr3133'SubFund',i.attr3226'Do Not Call',i.attr3209'Status',
'',i.attr3207'Insured Last Name',i.attr3206'Insured First Name',i.attr3210 as 'SSN',
'','','','',DATENAME(month,i.attr3225)'Date of Next Contact','','','','','',''
from hsi.rmobjectinstance1184 i,hsi.rmobjectinstance1183 p,
hsi.rmobjectinstance1180 sf,hsi.rmobjectinstance1178 f
where p.fk3186=sf.objectid and p.fk3183=i.objectid and sf.fk3144=f.objectid
and f.activestatus=0 and sf.activestatus=0 and p.activestatus=0 and i.activestatus=0 
and sf.attr3133='DB - LAT'
[COLOR=red]--and i.attr3209='Active'[/color]
and i.attr3210/*SSN*/ not in (select SSN from hsi.rmDeutscheLAT)

--Go
update hsi.rmDeutscheLAT set "Date of Next Contact"='DO NOT CALL',"Method of Contact"='DO NOT CALL' where "Do Not Call"=1
--go
update hsi.rmDeutscheLAT
set "Health Change Comments"=m.memo
from hsi.rmmemo m,hsi.rmDeutscheLAT d
where d.memoid=m.memoid
update hsi.rmDeutscheLAT set "Contact Information"='' where "contact Information" is null
--go
select "Case ID","Insured Last Name","Insured First Name","Tracking Status","Method of Contact","Date of Last Contact",
"Date of Next Contact","Respondent","Address Confirmation","Significant Changes in Health","Health Change Comments","SS Sweep Completed","Status"
from hsi.rmDeutscheLAT
order by LastContactDate desc,"Insured Last Name","Insured First Name"
 
Nevermind - I figured it out on my own. I added i.attr3209'Status' to the second select statement. However, I wasn't paying attention to the order of the coumns and added it to the middle, which got a char field aligned with a date column so it couldn't convert.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top