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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How do do A select and a Update/Insert in one query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-04-03 : 16:24:13
Johan Hanekom writes "Is their a better why to do the following with just a SQL Query rather than ADO?

Server: Ms SQL 6.5
OS: WinNT4/2k


'open connection to database
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & server.mappath("frontdoor/data_s/hardwired_stats.mdb")
SqlStatCheck = "SELECT * FROM tblStat where stat_time=" & DatePart("h",now()) & " and stat_day=" & DatePart("d",now()) & "and stat_month=" & DatePart("m",now())
Set RsStatCheck = Server.CreateObject("ADODB.Recordset")
RsStatCheck.Open SqlStatCheck, DSNtemp, 3, 3
'check to see if their is a record that is current
if RsStatCheck.eof then
'doesn't look like their is so we then add one
RsStatCheck.AddNew
RsStatCheck("stat_time") = DatePart("h",now())
RsStatCheck("stat_day") = DatePart("d",now())
RsStatCheck("stat_month") = DatePart("m",now())
RsStatCheck("stat_hit") = 1
RsStatCheck.Update
'response.write "Records Added"
else 'response.write "Records Found"
'update / add a value for the incoming hit
RsStatCheck("stat_hit") = RsStatCheck("stat_hit") + 1
RsStatCheck.Update
end if
'we redirect the user
Response.Redirect("frontdoor/default.asp")
Response.End
"
   

- Advertisement -