473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Select... Into... Having

JustJim
407 Expert 256MB
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 2399
JustJim
407 Expert 256MB
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 Expert 256MB
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 Expert 256MB
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 Expert 2GB
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 Expert 256MB
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
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...
3
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
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 {...
1
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...
4
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...
26
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...
22
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="...
0
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...
1
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...
0
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...

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.