Print Page | Close Window

Combine multiple sql calls into 1

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=17973
Printed Date: 29 March 2026 at 3:53am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Combine multiple sql calls into 1
Posted By: rx7tt
Subject: Combine multiple sql calls into 1
Date Posted: 15 January 2006 at 6:25pm
I have an old app that I'm trying to recode and improve performance.

From the start it makes three seperate calls to a db, checks to see if the record exists, if it doesn't it adds it, then takes the data from all three and inserts it into a final call.

Here is a quick example of the script

Select * from table1 where id = " & tempVariable
If Not RS.EOF Then
  strTable1 = RS("SomeRec")
Else
  RS.ADDNEW
  RS("SomeRec") = tempRec1
  RS.UPDATE
  RS.Requery
  strTable1 = RS("SomeRec")
End If
RS.CLOSE

Select * from table2 where id =2
If Not RS.EOF Then
  strTable2 = RS("SomeRec")
Else
  RS.ADDNEW
  RS("SomeRec") = tempRec2
  RS.UPDATE
  RS.Requery
  strTable2 = RS("SomeRec")
End If
RS.CLOSE

Select * from table3 where id =3
If Not RS.EOF Then
  strTable3 = RS("SomeRec")
Else
  RS.ADDNEW
  RS("SomeRec") = tempRec3
  RS.UPDATE
  RS.Requery
  strTable3 = RS("SomeRec")
End If
RS.CLOSE

INSERT INTO Table4 (Table1, Table2, Table3) VALUES ('" & strTable1 & "', '" & strTable2 & "', '" & strTable3 & "'


These is probably an easy solution however I don't know where to start. Any help or ideas will be greatly appreciated.
Thanks
-Scott


-------------
http://www.mobilegear.biz - Mobile Gear.biz -Ringtones, games, videos, links and more...
http://www.mobilegear.biz/forum/ - Wireless Forums



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net