Solved

SQL Text larger than 255 characters

Posted on 2008-06-18
8
737 Views
Last Modified: 2012-06-27
How can a pass an SQL text greater than 255 characters that has been stored in a table to the SQL property of a QueryDef?

In many words:
I have a table where I store the SQL to generate a report, field name is SQL2Use - a memo field as some of the SQL is quite long.

In my code I store the contents of SQL2Use in a variable sSQL2Use (declared as a variant) and later assign this to the SQL property of a qQueryDef as follows:

qdf.SQL = sSQL2Use

All works fine until I come across something with > 255 character.

My code sees only the text after the 1st 255 characters.

Can someone please help ?

TIA

Clemens
0
Comment
Question by:cpmasesa
  • 4
  • 3
8 Comments
 
LVL 10

Expert Comment

by:therealmongoose
ID: 21813970
hmm - not sure, but try declaring your variable as a string variable not a variant type...
0
 

Author Comment

by:cpmasesa
ID: 21814190
Thats what I did initially.  String has a limitation of 255 characters.  I looked fr a data type like LongChar, VarChar, Memo with no luck!

0
 

Author Comment

by:cpmasesa
ID: 21814440
I just went through my data, after your previous post, and realised that it actually works EXCEPT when I further need to manipulate what is in sSQL2Use

A code snippet:
'Get the relevant SQL for selected report
sSQL2Use = DLookup("SQL2Use", "_Report", "ReportID = " & cbReport.Value)

'Get user input, for what person do they want the report for
sUserInput = InputBox(sFilterField, "EDCTP Thingie", "")

'Assemble final SQL with filter as input by user
sSQL2Use = sSQL2Use & " " & sFilterVerb & " " & sFilterField & " = " & Chr(34) & sUserInput & Chr(34)
 
0
 
LVL 10

Accepted Solution

by:
therealmongoose earned 40 total points
ID: 21814764
try adding a debug line:

debug.print sSql2Use

This may help you see where the string build is falling over...
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 38

Expert Comment

by:Jim P.
ID: 21815222
I think I see what your problem is. The difference between the Access/JET string data type and the VB/VBA string data type.

From VB Help:
---------------------------------------------
String Data Type

There are two kinds of strings: variable-length and fixed-length strings.

A variable-length string can contain up to approximately 2 billion (2^31) characters.

A fixed-length string can contain 1 to approximately 64K (2^16) characters.
Note   A Public fixed-length string can't be used in a class module.
---------------------------------------------

The DLookup is a JET function and therefor defaults to the 255 limit of JET.

This is longer but the solution below.


Dim DB As DAO.Database

Dim RS As DAO.Recordset

Dim SQL As String
 

Dim FileNum As Integer

Dim OutputLine As String
 

FileNum = FreeFile()
 

'The SQL query to open the recordset

SQL = "SELECT SQL2Use " & _

    "FROM _Report " & _

    "WHERE ReportID = '" & cbReport.Value & "' "
 

Set DB = CurrentDb()                'Use the current database

Set RS = DB.OpenRecordset(SQL)      'actually open the recordset
 

If RS.EOF = False Then

    RS.MoveFirst

    sSQL2Use = RS!SQL2Use 

Else

    MsgBox "No Data", vbExclamation, "Exiting Fuction"

    Set RS = Nothing

    Set DB = Nothing

    Exit Function

End If

Set RS = Nothing

Set DB = Nothing

Open in new window

0
 

Author Comment

by:cpmasesa
ID: 21818535
Guys thank you.

I have resolved the problem.

Mostly due to therealmongoose: suggestion that I do a debug.print.  I then saw where I erred and corrected it. (The stored sql string had a WHERE clause and I was also adding one in my code)

Thank you all
0
 
LVL 10

Expert Comment

by:therealmongoose
ID: 21931672
Great - glad you have resolved - coulc you please allocate points appropriately and close the question....


Cheers,

Mongoose
0
 

Author Closing Comment

by:cpmasesa
ID: 31468413
Your suggest lead to me finding the error in my code, I resolved it.  Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS SQL - Rotating Values in SQL 9 53
Is it possible to reset DSum? 12 43
Excess tables to Excel BackUp 3 29
Web based Access Database and licencing 5 30
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now