Solved

TSQL date field (name)

Posted on 1998-10-06
12
161 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
  • 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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