more help with combining queries

# Thread: more help with combining queries

1. Dan D Guest

## more help with combining queries

The first block here is the two queries I need to combine. The second block is my attempt at combining the two. This has given me problems, though. Can you tell me what&#039s wrong with the second block?<BR><BR><BR>oQuery = "SELECT S6REGN, S6SRP3, S6AN8 FROM DBIPRDOBJ.SAWKL625 WHERE S6REGN = &#039" &_<BR>Request.Form("reg") & "&#039 and S6SRP3 = &#039"& Request.Form("class") & "&#039 and S6AN8 = &#039"&_ <BR>Request.Form("cust") & "&#039"<BR>oQuery = "SELECT S6BLYR, SUM(S6P1\$)as SUMS6P1, SUM(S6P2\$)as SUMS6P2, SUM(S6P3\$)as SUMS6P3, SUM(S6P1U)as SUMS6U1, SUM(S6P2U)as SUMS6U2, SUM(S6P3U)as SUMS6U3 FROM DBIPRDOBJ.SAWKL625 WHERE S6BLYR BETWEEN 1998 AND 2000 GROUP BY S6BLYR ORDER BY S6BLYR" <BR><BR><BR>oQuery = "SELECT S6REGN, S6SRP3, S6AN8, S6BLYR, SUM(S6P1\$)as SUMS6P1, SUM(S6P2\$)as SUMS6P2, SUM(S6P3\$)as SUMS6P3, SUM(S6P1U)as SUMS6U1, SUM(S6P2U)as SUMS6U2, SUM(S6P3U)as SUMS6U3 FROM DBIPRDOBJ.SAWKL625 WHERE S6REGN = &#039" &_<BR>Request.Form("reg") & "&#039 and S6SRP3 = &#039"& Request.Form("class") & "&#039 and S6AN8 = &#039"&_ <BR>Request.Form("cust") & "&#039 and S6BLYR BETWEEN 1998 AND 2000 GROUP BY S6BLYR ORDER BY S6BLYR"<BR>

2. Senior Member
Join Date
Dec 1969
Posts
745

## RE: more help with combining queries

&nbsp;<BR>your where claus is messed up try this:<BR><BR>oQuery = "SELECT S6REGN, S6SRP3, S6AN8, S6BLYR, SUM(S6P1\$)as SUMS6P1, SUM(S6P2\$)as SUMS6P2, SUM(S6P3\$)as SUMS6P3, SUM(S6P1U)as SUMS6U1, SUM(S6P2U)as SUMS6U2, SUM(S6P3U)as SUMS6U3 FROM DBIPRDOBJ.SAWKL625 WHERE S6REGN = &#039" &_<BR>Request.Form("reg") & "&#039" &_<BR>" and S6SRP3 = &#039"& Request.Form("class") & "&#039" &_<BR>" and S6AN8 = &#039" Request.Form("cust") & "&#039" &_<BR>" and S6BLYR BETWEEN 1998 AND 2000 GROUP BY S6BLYR ORDER BY S6BLYR"<BR>

3. Dan D Guest

## RE: more help with combining queries

I am still getting the same error<BR><BR>Microsoft OLE DB Provider for ODBC Drivers error &#039 80004005&#039 <BR>[IBM][Client Access ODBC Driver (32-bit)][DB2/400 SQL]SQL0401 - Comparison operator = operands not compatible. <BR><BR>/region.asp, line 70<BR> <BR>***line 70 comes right after this code:<BR>Set DSData = oSales.Execute(oQuery)<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
745

## RE: more help with combining queries

did you try to rename this field SUM(S6P1\$)to SUMS6P1 using "AS"?<BR>try not to use the word as instead use double quotes around new name e.g.<BR><BR>select sum(s6P1\$) "SUMS6P1" and so on...<BR><BR>hope this help<BR><BR>Michael<BR>

5. Senior Member
Join Date
Dec 1969
Posts
745

## RE: more help with combining queries

If the data type of the year is string you need single quote around 1998 and 2000.

6. Dan
Senior Member
Join Date
Dec 1969
Posts
1,364

## RE: more help with combining queries

I made both changes and I still get the same error message

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•