Results 1 to 4 of 4

Thread: SQL syntax

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    2
    What does the & _ symbols represent in an SQL statement?
    e.g.
    strSQL = "SELECT name, age FROM table WHERE " & _
    "name = '" &name& "'"

    Why are they in separate lines and what is the function of the "& _" symbol represented above?

  2. #2
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    The & _ is not part of the SQL statement. All that does is allow you to spread a statement over more than one line.

    This

    Code:
    strSomeString = "some text in a string"
    strSomeString = strSomeString & "more text for the string"
    strSomeString = strSomeString & "yet more text"
    Is the same as this

    Code:
    strSomeString = "some text in a string" & _
                    "more text for the string" & _
                    "yet more text"

  3. #3
    "name = '"&name&"'"

    it means that the second name ('"&name&"') is parameter

    eg.

    name = &_
    inputbox("Enter Your name ? ")

    strSQL = "SELECT name, age FROM table WHERE" &_
    "name = '"&name&"'"

    data1.recordsource = strsql

    it means that data1 recordsource will contain records which has name same with the name that you enter through the inputbox.

    thanks
    bambang

  4. #4
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84
    Hi there,

    1.)
    you can use a & to join two strings:
    e.g.

    string1 = "Hello "
    string2 = "World!"

    newstring = string1 & string2 '--> "Hello World"

    2.)
    with the underscore _ you can insert a linebreak into your code without VB complaining about it
    however there has to be a space before the underscore

    e.g.

    Code:
    if (condition2 or condition2) and condition3 _
    then dowhateveryouwant
    without the underscore VB would complain

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