Hi
Environment VB6 SP5
I'm attempting to dynamically build a SQL string in
VB for inclusion in a Command object. Attempting being the operative term in this instance.
I am having difficulty building a SQL string longer than 260 chars. I'm somewhat bemused by this one. My understanding is that String Variables hold monstrous numbers of characters(0 to approximately 2 billion according to MS).
The code is as follows:
Code:
'Refresh the Criteria Score
'Set AdoDC SQL statement to reflect the Country and Category chosen
sCategoryIdSelected = CStr(iCategoryIdSelected)
sCountryIdSelected = CStr(iCountryIdSelected)
sSQLCmd = ""
sSQLCmd = "SELECT b.Criteria, a.CriteriaId, a.CountryId, a.CategoryId, a.CountryCriteriaScore ,a.CountryCriteriaNotes" & _
" FROM TblCountryCriteria as a ,TblCriteriaDefinition as b" & _
" WHERE a.CategoryId = b.CategoryId " & _
" AND a.CriteriaId = b.CriteriaId "
iLen = Len(sSQLCmd)
sWhereClause = " AND a.CategoryId = " & sCategoryIdSelected
sWhereClause = sWhereClause & " AND a.CountryId = " & sCountryIdSelected
sWhereClause = "12345678901234567890123456789012345678901234567890123456789A"
sSQLCmd = sSQLCmd & sWhereClause
shows my test. I'm replacing the where clause with a string of numbers for test purposes. sSQLCmd is declared as string. Its length is 231.
The output for sSQLCmd from the watch window is as follows:
"SELECT b.Criteria, a.CriteriaId, a.CountryId, a.CategoryId, a.CountryCriteriaScore ,a.CountryCriteriaNotes FROM TblCountryCriteria as a ,TblCriteriaDefinition as b WHERE a.CategoryId = b.CategoryId AND a.CriteriaId = b.CriteriaId 1234567890123456789 "
This demonstrates that the string that I attempt to concatenate onto sSQLCmd gets truncated. Not entirely the effect I was after!:(
Unless my simple maths has flaked out and there is some curious quantum effect happening I should be able to make this concatenation without any issue. Any ideas?
The answer is probably very simple