home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / DOS / Programa / TI2948.ZIP / TI2948.ASC < prev   
Encoding:
Text File  |  1996-06-17  |  3.6 KB  |  108 lines

  1.    NUMBER  :  2948
  2.   PRODUCT  :  Delphi
  3.   VERSION  :  All
  4.        OS  :  Windows/Win32
  5.      DATE  :  June 14, 1996                           
  6.  
  7.     TITLE  :  SQL: Embedded Spaces in Field/Column Names
  8.  
  9. Implementing SQL with spaces or special characters in field/column names
  10.  
  11. Implementing SQL statements in Delphi's TQuery component (or the
  12. SQL query facilities of Database Desktop, Visual dBASE or Paradox
  13. for Windows) requires special syntax for any columns that contain
  14. spaces or special characters.
  15.  
  16. Using the Biolife.DB table of from Delphi's demo data to
  17. illustrate, and without the use of any special syntax
  18. requirements, a SQL Select statement might be formed as follows,
  19.  
  20. SELECT
  21.  Species No,
  22.  Category,
  23.  Common_Name,
  24.  Species Name,
  25.  Length (cm),
  26.  Length_In,
  27.  Notes,
  28.  Graphic
  29. FROM
  30.  BIOLIFE
  31.  
  32. While appearing normal, the space in the species number and name
  33. columns and the column expressing length in centimeters - as well
  34. as the parentheses present - cause syntax errors.
  35.  
  36. Two changes must be taken to correct the syntax of the above SQL
  37. statement.  First, any columns containing spaces or special
  38. characters must be surrounded by single (apostrophe) or double
  39. quotes.  Secondly, a table reference and a period must precede
  40. the quoted column name.  This second requirement is particularly
  41. important since a quoted string alone is interpreted as a string
  42. expression to be yielded as a column value.  A properly formatted
  43. statement follows:
  44.  
  45. SELECT
  46.  BIOLIFE."Species No",
  47.  BIOLIFE."Category",
  48.  BIOLIFE."Common_Name",
  49.  BIOLIFE."Species Name",
  50.  BIOLIFE."Length (cm)",
  51.  BIOLIFE."Length_In",
  52.  BIOLIFE."Notes",
  53.  BIOLIFE."Graphic"
  54. FROM
  55.  "BIOLIFE.DB" BIOLIFE
  56.  
  57. The above example uses the table alias BIOLIFE as the table
  58. reference that precedes the column name.  This reference may take
  59. the form of an alias name, the actual table name, or a quoted
  60. file name when using dBASE or Paradox tables.  The following
  61. SQL statements would serve equally well.
  62.  
  63. Note: This SQL statement may be used provided that the necessary
  64. alias is already opened.  In the case of the TQuery this means the
  65. alias is specified in the DatabaseName property.
  66.  
  67. SELECT
  68.  BIOLIFE."Species No",
  69.  BIOLIFE.Category,
  70.  BIOLIFE.Common_Name,
  71.  BIOLIFE."Species Name",
  72.  BIOLIFE."Length (cm)",
  73.  BIOLIFE.Length_In,
  74.  BIOLIFE.Notes,
  75.  BIOLIFE.Graphic
  76. FROM
  77.  BIOLIFE
  78.  
  79. If an alias is not available then the entire path to the table
  80. can be specified as in this example:
  81.  
  82. SELECT
  83.  "C:\DELPHI\DEMOS\DATA\BIOLIFE.DB"."Species No",
  84.  "C:\DELPHI\DEMOS\DATA\BIOLIFE.DB"."Category",
  85.  "C:\DELPHI\DEMOS\DATA\BIOLIFE.DB"."Common_Name",
  86.  "C:\DELPHI\DEMOS\DATA\BIOLIFE.DB"."Species Name",
  87.  "C:\DELPHI\DEMOS\DATA\BIOLIFE.DB"."Length (cm)",
  88.  "C:\DELPHI\DEMOS\DATA\BIOLIFE.DB"."Length_In",
  89.  "C:\DELPHI\DEMOS\DATA\BIOLIFE.DB"."Notes",
  90.  "C:\DELPHI\DEMOS\DATA\BIOLIFE.DB"."Graphic"
  91. FROM
  92.  "C:\DELPHI\DEMOS\DATA\BIOLIFE.DB"
  93.  
  94. Finally, two facilities that automatically handle this special
  95. formatting exist.  The first is the Visual Query Builder that is
  96. a part of the Client/Server version of Delphi.  The Visual Query 
  97. Builder performs this formatting automatically as the query is built.
  98. The other facility is Database Desktop's Show SQL feature, available
  99. when creating or modifying a QBE-type query.  After selecting
  100. Query|Show SQL from the main menu, the displayed SQL text may be
  101. cut and pasted where needed.
  102.  
  103.  
  104. DISCLAIMER: You have the right to use this technical information
  105. subject to the terms of the No-Nonsense License Statement that
  106. you received with the Borland product to which this information
  107. pertains.
  108.