Results 1 to 7 of 7

Thread: SQL statement

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    SQL statement

    Hi All,

    What is wrong with this SQL statment, as VB does not like it

    VB Code:
    1. rst.Open "SELECT Controller.FirstName, Controller.Lastname, Controller.Time, Controller.Teachers_Name From Controller=WHERE (((Controller.Time)="17:00") AND ((Controller.Teachers_Name)="Lauren ellis"))", Adodc1.ConnectionString, adOpenKeyset, adLockOptimistic

    Thnaks

    Loftty

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL statement

    TIME is a reserved word - you should avoid field names with reserved words.

    See the link in my signature for a list of other reserved words.

    You can overcome the problem by wrapping the column name in []-brackets, but that doesn't always work (bugs in some tools make the field simply not accessible).

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: SQL statement

    Hi,

    I have changed the time to Time_Lesson

    but I get an error saying expected end of statement and points to 17

    VB Code:
    1. rst.Open "SELECT Controller.FirstName, Controller.Lastname, Controller.Time_Lesson, Controller.Teachers_Name From Controller WHERE (((Controller.Time_Lesson)="17:30")" AND ((Controller.Teachers_Name)="ben riches"))", Adodc1.ConnectionString, adOpenKeyset, adLockOptimistic

    What am I doing wrong here?

    Thanks

    Loftty

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: SQL statement

    Use single quotes to delimit the values within the string and double quotes to delimit the entire string

    VB Code:
    1. WHERE (((Controller.Time_Lesson)="17:30")" AND ((Controller.Teachers_Name)="ben riches"))", adodc
    2.  
    3. should be
    4.  
    5. WHERE (((Controller.Time_Lesson)='17:30') AND ((Controller.Teachers_Name)='ben riches'))", adodc

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL statement

    Quote Originally Posted by brucevde
    Use single quotes to delimit the values within the string and double quotes to delimit the entire string

    VB Code:
    1. WHERE (((Controller.Time_Lesson)="17:30")" AND ((Controller.Teachers_Name)="ben riches"))", adodc
    2.  
    3. should be
    4.  
    5. WHERE (((Controller.Time_Lesson)='17:30') AND ((Controller.Teachers_Name)='ben riches'))", adodc
    I didn't even scroll that far over!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: SQL statement

    Hi,

    Done what you said by using singe quotes, thankyou, how can I see the output that I get?

    Thanks

    Loftty

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL statement

    The RST object has property and methods - look up help file on RECORDSET object...

    Here a really simply snippet - there is more to this (moving to next record - stuff like that).

    Code:
        rs.Open "SELECT dbo.GetConf('" & ConfItem _
            & "') as ConfData", gCn
        GetConf = rs!ConfData & ""
        
        rs.Close
        Set rs = Nothing

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width