Solved

TSQL date field (name)

Posted on 1998-10-06
12
162 Views
Last Modified: 2010-04-06
How can I retreive data from a field who fieldname is an reserved word ( Date, Time, etc.)
0
Comment
Question by:lortega
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1342013
Hi lortega,

Label1.Caption := Table1.FieldByName('Date').AsString;
or
Label1.Caption := Table1.FieldByName('Date').AsInteger;
or
.

Regards, Zif.
0
 
LVL 1

Expert Comment

by:tha_incredible_bo
ID: 1342014
hi Iortega,

try to put the name of the field in double-quotes e.g. select "Date" from ... or if you are working with an SQL-Server: select tablename.Fieldname from ...
0
 
LVL 2

Author Comment

by:lortega
ID: 1342015
I need something like...

Select * from myTable Where Date = '8/4/98'

where Date is the name of the field...

note on Oracle or MSSQL you should write the fieldname between brackets  []...
Select * from myTable Where [Date] = '8/4/98'

but who to do this on Delphi (TQuery)?

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:lortega
ID: 1342016
tha_incredible_bo set your awnser, because is a mix of your awnser...


Select * from myTable Where HistoryDB."Date" = '8/4/98'

note:
Select * from myTable Where "Date" = '8/4/98'    // Don't work
Select * from myTable Where HistoryDB.Date = '8/4/98'   // Don't work


thank's
lortega
0
 
LVL 2

Author Comment

by:lortega
ID: 1342017
tha_incredible_bo set your awnser, because is a mix of your awnser...


Select * from myTable Where HistoryDB."Date" = '8/4/98'

note:
Select * from myTable Where "Date" = '8/4/98'    // Don't work
Select * from myTable Where HistoryDB.Date = '8/4/98'   // Don't work


thank's
lortega
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1342018
Ok, now I understand what you want.

doesn't this works :

Select *
from MyTable M
where M.Date = 'Snapper'

Regards, Zif


0
 
LVL 10

Expert Comment

by:Jacco
ID: 1342019
Changing the fieldname is not an option I suppose?

I use dates with a prefix:

Arrival_Date
Depart_Date
Trace_Date
Action_Date
Orig_Date
etc.

Regards Jacco
0
 
LVL 1

Accepted Solution

by:
tha_incredible_bo earned 30 total points
ID: 1342020
hi Iortega,

I tried to write a little bit code concerning your problem and found the following result:

with this sql-statement select * from "f:\pdoxdb\test" where "date" ="" everything is allright (concering the date field). the only thing you must pay attention (for correct results) is the format of your date-field! this belongs to your database-type. e.g. some databases use an internal date format and so you have to cast your input date (10.10.98) to this internal format (sometimes) - so please be careful.

cu
Bo
0
 
LVL 2

Author Comment

by:lortega
ID: 1342021
Jacco if I change the fieldname, I have to go tru all our clients... and we are not MS  :-)
but this kind of thinks help us in the future.

ZifNab your solution works if I use MS database, but I don't know why don't work here  :-(

tha_incredible_bo I realy don't know who create this database, but the fieldname is Date and the field format is character (string)... hummmmm...

thanks
luis
0
 
LVL 1

Expert Comment

by:tha_incredible_bo
ID: 1342022
hi Iortega,

very strange field-format, isn't it ???? Try to find the one who defined the database structure and the field-formats and buy him a lollypop ... :-)))

Do you leave the format unchanged or will you change it??? If you leave the format there should be a format-procedure which should insure an everytimes equal format result before writing to the database except you will sooner or later run into troubles (inconsitency or wrong search results) !!!

CU
Bo


0
 
LVL 2

Author Comment

by:lortega
ID: 1342023
We don't have permison to change fields until next version or release :-(
but I wil take care of that...

thanks
luis
0
 
LVL 1

Expert Comment

by:tha_incredible_bo
ID: 1342024
bad luck Iortega! think about the procedure (if it is not too late)?!

keep it up
CU
Bo ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question