Constructing Strings in Visual Basic

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • clarencelai
    New Member
    • Oct 2007
    • 44

    Constructing Strings in Visual Basic

    Hi all,

    I need to run a SQL statement in Microsoft VB.

    The following statement returns an error "Compile Error: Expected: end of statement". yyyy was highlighted when the error was encountered.

    I believe that there are something wrong with my syntax. It could be the quotes (") that I have used to enclose the date format.

    I would appreciate if anyone could help to correct.

    *************** *************** *************** ***

    strSQL = "SELECT DISTINCT Min(Format([SHOW_DATE],"yyyy/mm/dd")) AS [Start Date], Max(Format([SHOW_DATE],"yyyy/mm/dd")) AS [End Date] INTO NewSurveys" _
    & "From STIXMV_EVENT_SH OW HAVING (((Max(Format([SHOW_DATE],"yyyy/mm/dd")))=Format(D ate()-15,"yyyy/mm/dd")));"
    *************** *************** *************** ***

    Regards,
    Clarence
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Originally posted by clarencelai
    Hi all,

    I need to run a SQL statement in Microsoft VB.

    The following statement returns an error "Compile Error: Expected: end of statement". yyyy was highlighted when the error was encountered.

    I believe that there are something wrong with my syntax. It could be the quotes (") that I have used to enclose the date format.

    I would appreciate if anyone could help to correct.

    *************** *************** *************** ***

    strSQL = "SELECT DISTINCT Min(Format([SHOW_DATE],"yyyy/mm/dd")) AS [Start Date], Max(Format([SHOW_DATE],"yyyy/mm/dd")) AS [End Date] INTO NewSurveys" _
    & "From STIXMV_EVENT_SH OW HAVING (((Max(Format([SHOW_DATE],"yyyy/mm/dd")))=Format(D ate()-15,"yyyy/mm/dd")));"
    *************** *************** *************** ***

    Regards,
    Clarence
    Hi

    You need to duplicate all the quotation marks that are part of the string (those that do not start or end the string) like this

    strSQL = "SELECT DISTINCT Min(Format([SHOW_DATE],""yyyy/mm/dd"")) AS [Start Date], Max(Format([SHOW_DATE],""yyyy/mm/dd"")) AS [End Date] INTO NewSurveys " _
    & "From STIXMV_EVENT_SH OW HAVING (((Max(Format([SHOW_DATE],""yyyy/mm/dd"")))=Format( Date()-15,""yyyy/mm/dd"")));"

    By doing this the complier/interpreter/parser know when you want a quotation mark in the string and where the string starts and stops!


    HTH


    MTB

    Comment

    • clarencelai
      New Member
      • Oct 2007
      • 44

      #3
      Hi..

      Thanks for your help!

      Regards,
      Clarence


      Originally posted by MikeTheBike
      Hi

      You need to duplicate all the quotation marks that are part of the string (those that do not start or end the string) like this

      strSQL = "SELECT DISTINCT Min(Format([SHOW_DATE],""yyyy/mm/dd"")) AS [Start Date], Max(Format([SHOW_DATE],""yyyy/mm/dd"")) AS [End Date] INTO NewSurveys " _
      & "From STIXMV_EVENT_SH OW HAVING (((Max(Format([SHOW_DATE],""yyyy/mm/dd"")))=Format( Date()-15,""yyyy/mm/dd"")));"

      By doing this the complier/interpreter/parser know when you want a quotation mark in the string and where the string starts and stops!


      HTH


      MTB

      Comment

      Working...