Board index » delphi » Local SQL Insert and Spaces in field names

Local SQL Insert and Spaces in field names

Hi,

I made the mistake of using spaces in field names.  Now, it would be a pain
to try to find and change all the names.  Some of them are imbedded in TSQL
statements so even "Find in files" won't dig them all out.

Anyway, I've always been able to get SQL Selects to work OK by enclosing
the field name in quotes.  However, that doesn't seem to work in an SQL
Insert.

The following SQL generates an "Invalid use of keyword: , Line Number 3"
error.

Insert Into Transactions
   (SecID, TranDate, TranTime, TranType,
    TotalAmt, "Total Shares", Taxable)
   Values (:SecID, :TranDate, :TranTime, 'Split',
     0.0, :TotalShares, False)

Is there any way around this?

I tried

Insert Into Transactions a
   (a.SecID, a.TranDate, a.TranTime, a.TranType,
    a.TotalAmt, a."Total Shares", a.Taxable)
   Values (:SecID, :TranDate, :TranTime, 'Split',
     0.0, :TotalShares, False)

but I found you can't use an alias in an Insert statement.

Thanks for your help.

Ed

--
Ed Hochman - MBH Systems

 

Re:Local SQL Insert and Spaces in field names


On 12 May 1999 21:14:16 GMT, Ed Hochman <e...@nospam.mbhsys.com> wrote:

Quote
>I made the mistake of using spaces in field names.  Now, it would be a pain
>to try to find and change all the names.  Some of them are imbedded in TSQL
>statements so even "Find in files" won't dig them all out.

To use columns that have spaces embedded in their names in local SQL
statements, you need to do two things:

1. Enclose the column name in quotation marks.
2. Prefix the quoted reference with the table name or correlation name.

For example:

  INSERT INTO Transactions
  (SecID, TranDate, TranTime, TranType, TotalAmt,
    Transactions."Total Shares", Taxable)
  VALUES (:SecID, :TranDate, :TranTime, "Split",
    0.0, :TotalShares, False)

//////////////////////////////////////////////////////////////////////////
Steve Koterski                    "My problem lies in reconciling my gross
Technical Publications            habits with my net income."
INPRISE Corporation                             -- Errol Flynn (1909-1959)
http://www.borland.com/delphi

Other Threads