SQLTeam.com | Weblogs | Forums

Combining two queries into one output


#1

Hi all,

I'm just very new to SQL so, maybe this is a very basic question but I will ask it anyway. What I want to do is the following:

On the same table, I want to run two queries, which will look like this:

  1. Field1 >=#1-1-2008# AND Field2 > 20080000, then a number of field need to be included from the selected records
  2. Field1=Null AND Field2 > 20080000 AND Field3>=#1-1-2008#, then the same fields which are selected in the first query need to be included.

Problem that I now encounter (I'm working in MS Access) is that I can create these queries individually, then combine the output in a UNION query, but this UNION query is not updatable. This is a big problem, because the exact purpose of both queries is to make a selection which can be updated.

My question is: is there a way to write both queries in SQL and directly combine/write the output into one format? So that it will be updatable, and changes will be written to the original tables?

Thanks in advance!


#2

Store the IDs / PKeys of the records, from the UNION query, into a Temp Table and then JOIN that to the original table for the UPDATE ?


#3

Could you just use one query with a WHERE clause like this:

WHERE (Field1 >=#1-1-2008# AND Field2 > 20080000)
   OR (Field1 Is Null AND Field2 > 20080000 AND Field3>=#1-1-2008#)