PDA

Click to See Complete Forum and Search --> : SQL syntax (beginner)


bontyboy
Feb 14th, 2000, 07:31 PM
I am trying to write an SQL statement and I can't get the syntax right for it to work. Is there a site that I can learn the SQL syntax? Thanks

Here's the Function:

Public Function GetClient(sClientName As String) As String
Dim sSQL As String
Dim sName As String
sSQL = "SELECT * From Customers " & "WHERE Customers.Contact Name = '" & sClientName & "'"

Set rs = MyDb.OpenRecordse (sSQL,dbOpenDynaset)


rs.Close
End Function

[This message has been edited by bontyboy (edited 02-15-2000).]

Feb 15th, 2000, 06:34 AM
sSQL = "SELECT * From Customers "
sSQL = sSQL & "WHERE Contact Name = '"
sSQL = sSQL & sClientName & "'"

check an make sure there is/isn't a space in contact name field



[This message has been edited by BG (edited 02-15-2000).]

Clunietp
Feb 16th, 2000, 11:15 AM
Change Contact Name to [Contact Name]

(use brackets for fields with spaces)

SQL tutorial @ http://w3.one.net/~jhoffman/sqltut.htm

benpartlow
Feb 17th, 2000, 04:32 AM
Try using "LIKE" instead of =

ermingut
Feb 17th, 2000, 05:21 AM
That must work.

dim MyDb as Database
dim RS as recordset

set MyDb=OpenDatabase("c:\db.mdb")
sSQL="SELECT * FROM Customers where Contact_Name=' " & sClientName & " ' "
set RS =MyDb.OpenRecordset(sSQL,dbOpenDynaset)

' I'm not shure that SQL allows space in field name ("Contact Name") so use field name like Contact_name or use brackets.

Gimpster
Feb 17th, 2000, 05:53 AM
Also, here (http://w3.one.net/~jhoffman/sqltut.htm) is a great site for a quick overview of SQL and how to use it. Print it out and have it by your computer whenever you are going to be using SQL.

------------------
Ryan