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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch error 1

Status
Not open for further replies.

DotNetDunce

Programmer
Aug 23, 2001
47
0
0
US
I am getting a type mismatch error when this reaches the last line of the sub. Can someone help me figure out why this doesn't work?

post_id is a numeric field.

Thanks in advance for your help!


Code:
Sub Delete_Recs(post_id)
	set rs2 = Server.CreateObject("ADODB.recordset")
	sql2_abbs = "DELETE FROM Posts WHERE post_id = " & post_id
	response.write sql2_abbs & "<br>"
	rs2.open, sql2_abbs, conn
End Sub

	Conn.Open
	Set rs = Server.CreateObject("ADODB.Recordset")
	sql_abbs = "SELECT * FROM posts"
	rs.Open sql_abbs, conn

	cnt=0
	cnt2=0
	Do while not rs.eof
	'response.write (DateDiff("m", Now, rs("date")))
		if DateDiff("m", Now, rs("date")) <=-6 then
			cnt2=cnt2+1
			Call Delete_Recs(rs("post_id"))
			response.write "Records Deleted<br>" & cnt2 & "<br>"
		else
			cnt = cnt + 1
			'response.write "<font color='blue'>Record not ready for deletion" & response.write(cnt) & "</font><br>"
		end if
	rs.movenext
	loop
	
	conn.close
	
%>
 
Remove the first comma from that line, but leave the second one.



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Looking at your code a little closer....

Are you really returning ALL the data in the table, looping to figure out which one to delete, and then deleting one by one?

This procedure may work well for you in a test environment, where there are only a couple records in the table, but there is a MUCH better way to do this.

If you are interested, let me know.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I cannot believe I had that extra comma there and didn't see it and, yes, George (gmmastros), I would love a better way to do this. I just threw this together this morning to create a scheduled task and this was the first thing that came to mind.

Thanks everyone for your help. Sometimes you just need a fresh set of eyes. :)
 
Well....

You can accomplish the same thing with a single call to the database. There will be less 'round trips' and the entire operation will happen faster. The exact syntax will depend on the database engine you are using.

For SQL Server...

Code:
Delete
From   Posts
Where  Date < DateAdd(Month, -6, GetDate())

The syntax will be similar, but different, for other database engines.



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you so much for that information. I had that idea in mind when I started, but wasn't sure exactly how to accomplish it.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top