Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 An expression of non-boolean type specified in ...

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2009-04-09 : 23:04:16
Dear All,

I'm getting error :-
An expression of non-boolean type specified in a context where a condition is expected, near ' membershipid between 1 and 100'.


This is my portion of Dll sourcecode:-

Public Function Query( _
ByVal userCode As String, _
ByVal connectionStr As String, ByVal tableName As String, ByVal fieldName As String) As ADODB.Recordset

1 On Error GoTo Catch
Try:
Dim recObj As ADODB.Recordset
2 Set recObj = New ADODB.Recordset
Dim sqlStr As String
Dim fso As New Scripting.FileSystemObject
Dim txtFile As Scripting.TextStream

' Set it up
3 recObj.CursorLocation = adUseClient
4 recObj.CursorType = adOpenStatic
5 recObj.LockType = adLockBatchOptimistic

6 recObj.ActiveConnection = connectionStr

sqlStr = "SELECT * FROM [" & tableName & "] WHERE [" & fieldName & "] "

' Run the underlying stored procedure to get the recordset
7 recObj.Open sqlStr, , , , adCmdText




This is my ASP Classic Page:-

Set insertObj = Server.CreateObject("COM1011.bcExportText")

'Response.END

Set BigCom = insertObj.Query(thisMemberCode, conn,"memberships"," membershipid between 1 and 100")



Anyone know what goes wrong? Please advise.


Thank you.

Regards,
Michelle

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-04-10 : 07:34:23
It's your square brackets that are causing the problem. The way you have written the code, the query sent to the server is
select * from [memberships] where [ membershipid between 1 and 100]
If you change the code to
sqlStr = "SELECT * FROM [" & tableName & "] WHERE " & fieldName
it will work for this specific example. If you want to escape the column names in the where condition using square brackets, you can escape them in the parameters you sent in - like this
Set BigCom = insertObj.Query(thisMemberCode, conn,"memberships"," [membershipid] between 1 and 100")
Go to Top of Page
   

- Advertisement -