Solved

TSQL date field (name)

Posted on 1998-10-06
12
154 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 2

Author Comment

by:lortega
Comment Utility
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
Comment Utility
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
Comment Utility
Ok, now I understand what you want.

doesn't this works :

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

Regards, Zif


0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Expert Comment

by:Jacco
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
bad luck Iortega! think about the procedure (if it is not too late)?!

keep it up
CU
Bo ;-)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now