473,789 Members | 2,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select... Into... Having

JustJim
407 Recognized Expert Contributor
I think I've just bumped into the limits of the Having Clause (Help file says 40 expressions, Mary says 99 and I know who I trust).

The question is, what happens if you overload the select... into... having clause? Does the whole thing fail? Is the clause truncated somehow?

It appears that the target table is being deleted, but then not re-created!

Here's what I got so far. Please pardon the long lines, I don't type 'em, I just paste from SQL view of the query designer!

Expand|Select|Wrap|Line Numbers
  1. '   Canberra Site Report export to Excel
  2.     If Sbf.SourceObject = "sfmSiteOnlyCanberra" Then
  3.             strExportTableName = "tblXLCanberraSites"
  4.         '   Gather the selected Projects
  5.         For Each varSelect In Sbf.Controls("lstSite").ItemsSelected
  6.             strOr = strOr & "(tblSite.SiteNo) = '" & Sbf.Controls("lstSite").ItemData(varSelect) & "' Or "
  7.         Next varSelect
  8.     '   lose the last ' OR '
  9.     strOr = Left(strOr, Len(strOr) - 4)
  10.     If strOr <> "" Then
  11.         strOr = "(" & strOr & ")"
  12.     End If  '   strOr <> ""
  13.  
  14.     strSQL = "SELECT tblSite.SiteNo, tblSite.SiteDescription, tblSite.NatMapRefN, tblSite.NatMapRefE, tblSite.MapNo, tblSite.GISZoneNo, qryAWName.NamCatch, qryAWName.NamSub, tbzElectorate.Electorate, tbzWaterType.WaterTypeDesc, tbzParam.DescShort, tblSample.SamNo, tblSample.Date " _
  15.         & "INTO " & strExportTableName & " " _
  16.         & "FROM tbzWaterType RIGHT JOIN (tbzParam RIGHT JOIN (((tblSite INNER JOIN qryAWName ON tblSite.AWCode = qryAWName.AWCode) INNER JOIN tbzElectorate ON tblSite.ElectID = tbzElectorate.ElectID) LEFT JOIN ((tblMonSite LEFT JOIN tblSample ON tblMonSite.GSPNo = tblSample.GSPNo) LEFT JOIN tblResult ON tblSample.SamNo = tblResult.SamNo) ON tblSite.SiteNo = tblMonSite.SiteNo) ON tbzParam.ParamNo = tblResult.ParamNo) ON tbzWaterType.WaterType = tblSite.WaterType " _
  17.         & "WHERE (((tblSite.SiteActive)=True)) " _
  18.         & "GROUP BY tblSite.SiteNo, tblSite.SiteDescription, tblSite.NatMapRefN, tblSite.NatMapRefE, tblSite.MapNo, tblSite.GISZoneNo, qryAWName.NamCatch, qryAWName.NamSub, tbzElectorate.Electorate, tbzWaterType.WaterTypeDesc, tbzParam.DescShort, tblSample.SamNo, tblSample.Date "
  19.     If strOr <> "" Then
  20.         strSQL = strSQL & " HAVING " & strOr
  21.     End If  '   strOr <> ""
  22.  
  23.     'Make note of any fields that have to have their data type fixed
  24.     ReDim arFixField(1, 0)
  25.     arFixField(0, 0) = "SamNo"
  26.     arFixField(1, 0) = "INTEGER"
  27.     iArrayCounter = 0
  28.     DoCmd.SetWarnings False
  29.     If Application.CurrentData.AllTables(strExportTableName).IsLoaded Then
  30.         DoCmd.Close acTable, strExportTableName, acSaveNo
  31.     End If  '   Application.CurrentData.AllTables(strExportTableName).IsLoaded
  32.     DoCmd.RunSQL strSQL
  33.     For iLoop = 0 To iArrayCounter  '   fix up any column datatypes as noted earlier
  34.         strExecuteCommand = "Alter Table " & strExportTableName & " ALTER COLUMN " & arFixField(0, iLoop) & " " & arFixField(1, iLoop)
  35.         DoCmd.RunSQL strExecuteCommand
  36.     Next iLoop
  37.  
Depending on the user's back end tables and the choices they make from the multi-select listbox, this can end up with a len(strSQL) of > 11,000!, but that's within the 32,768 limit.

Oddly, when no table is created, the second RunSQL action (to fix up datatypes) doesn't cause an error.

Jim
Oct 25 '07 #1
5 2414
JustJim
407 Recognized Expert Contributor
Stop Press!

I just noticed that when the operator makes no choice from the listbox, (making strOR = "" and therefore there is no Having clause at all), the same thing happens! The table is deleted but not re-created and the second RunSQL doesn't cause an error. (I rem'd out the SetWarnings False first).

If I paste strSQL into the SQL view of the query designer it works fine with a small Having clause or without one.

Things that make you go "Hmmm"

Jim
Oct 25 '07 #2
JustJim
407 Recognized Expert Contributor
Stop Press!

If I paste strSQL into the SQL view of the query designer it works fine with a small Having clause or without one.

Jim
Actually, that turns out not to be the case. If I paste strSQL into the SQL view of the query designer, I can view the query in Datasheet view, but if I run the query I get

"You tried to assign the Null value to a variable that is not a Variant
data type"

Still hunting!

Jim
Oct 25 '07 #3
JustJim
407 Recognized Expert Contributor
Actually, that turns out not to be the case. If I paste strSQL into the SQL view of the query designer, I can view the query in Datasheet view, but if I run the query I get

"You tried to assign the Null value to a variable that is not a Variant
data type"

Still hunting!

Jim
Got it!

It was the null value that put me onto it. One (and darn it, only one) of the Dates in tblSample were Null and that threw the whole thing out.

Big thanks to me for all my help! (No, not being snippy, I'm actually glad I sorted it myself)

Have a great weekend all.

Jim
Oct 25 '07 #4
missinglinq
3,532 Recognized Expert Specialist
We just love listening to your accent, mate! You understand, of course, that being "Down Under," everything you do in Access works bass ackwards!

Linq ;0)>
Oct 26 '07 #5
JustJim
407 Recognized Expert Contributor
We just love listening to your accent, mate! You understand, of course, that being "Down Under," everything you do in Access works bass ackwards!

Linq ;0)>
Crikey! That explains a lot.
Jim (.^.) that's me smiling down-side-up!
Oct 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

17
14647
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to allow entry to one or the other or Both at the same time. Now I tried to use an If ElseIf but it got too hard to track, so now I am using a SELECT CASE Statement.
3
3548
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
5
11509
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold { CarsSoldID int (primary key) MonthID int DealershipID int NumberCarsSold int
1
2072
by: Adam Balgach | last post by:
I am having a bit of a problem, and it might have to do with my understanding of how select works... basically what i am trying to simulate is a system: client->gateway->server model. The client breaks a file up into sections and sends them to the server, through teh gateway which just forwards info. Now upon getting the info, the server sends back an ACK through the gateway, when the client sees the ack it sends the next part...
4
2866
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table that links to a transaction items table that links to the products table: (User Table) UserID Other user data
26
17214
by: GreatAlterEgo | last post by:
Hi, This is my query which is embedded in a COBOL program. EXEC SQL SELECT DATE, AGE, DURATION, AMT INTO :LDATE, :L.AGE, :L.DURATION, :L.AMT FROM TAB1 WHERE CODE = :KEY.CODE AND SET = :KEY.SET AND DATE <= :KEY.DATE
22
12495
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient moConn.Mode = adModeReadWrite' or using default...same result
0
1997
by: pekx | last post by:
Hi, I create a script to pick up those records with duplication of IMIPROPSERVNO field, see below test1.sql, which is working.... test1.sql 1.SELECT IMIPROPSERVNO, COUNT(*) 2.FROM INSTALL_MASTER#IMIPROPSERN 3: GROUP BY IMIPROPSERVNO 4: HAVING COUNT(*) > 1; Now, I want a list of records in INSTALL_MASTER#IMIPROPSERN where the count > 1, ie those records with duplicated IMIPROPSERVNO. I tried the following but did not...
1
8063
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just a commandbutton on my form). The biggest problem I'm having is that I can't (don't know how) populate a combobox on static items such as "True, False, Any." The Any field, would be selected by the user to find all records where that fields is...
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.