Query on SQL database view using ODBC connection

I have just created an agent using Lotus script to query an SQL database view. However the lastname and surname field come back with False instead of the data they contain. The agent is connecting correctly to the datasource and brings back the correct number of results but the data within each field says False.

May have missed something so obtained sample script from the help file and it still brings back the same result. My script is as follows and any pointers would be appreciated.

Dim con As New ODBCConnection

Dim qry As New ODBCQuery

Dim result As New ODBCResultSet

Dim employeeNo As String

Dim firstName As String

Dim lastName As String

Dim msg As String

Set qry.Connection = con

Set result.Query = qry

con.ConnectTo("Export")

qry.SQL = "SELECT * FROM DOMINO_EXPORT WHERE SURNAME LIKE 'Crimmins'"

result.Execute

msg = "Employee names:" & Chr(10)

If result.IsResultSetAvailable Then

	Do

		result.NextRow

		If result.IsValueNull("empid") Then

			employeeNo = "None"

		Else

			employeeNo =  _

			result.GetValue("empid", _

			empid)

		End If

		If result.IsValueNull("FIRSTNAME") Then

			firstName = "None"

		Else

			firstName = _

			result.GetValue("FIRSTNAME", firstName)

		End If

		If result.IsValueNull("SURNAME") Then

			lastName = "None"

		Else

			lastName = _

			result.GetValue("SURNAME", lastName)

		End If

		msg = msg & Chr(10) & _

		studentNo & " " & firstName & " " & lastName

	Loop Until result.IsEndOfData

Else

	Messagebox "Cannot get result set for Employees"

	Exit Sub

End If

Messagebox msg,, "Employee Names"

con.Disconnect

Subject: Query on SQL database view using ODBC connection

Patrick, I had issues doing this as well. I think I ended up having to use result.GetValue(1) etc. where 1 is the first field in the query you are bringing back. SQL server didn’t seem to like the actual field names with the GetValue method.

Dustin

Subject: RE: Query on SQL database view using ODBC connection

Dustin, thanks for taking time to respond my question. I changed my script as suggested but still does not work. However it does display numeric data that I have contained within the field so will explore this angle.

Once again thanks for your help.

Subject: RE: Query on SQL database view using ODBC connection

Patrick,you must declare/convert eacht of these fields to “character”.

So try:

qry.SQL = "SELECT DISTINCT convert(char, FIRSTNAME) as FIRSTNAME, …

Gerhard

Subject: RE: Query on SQL database view using ODBC connection

Gerhard

It works perfectly thank you for taking the time to respond to my post.

Regards

Pat