How to add and subtract one second from a timestamp column - Sybase ASE 12.5

Hello Experts!!!
I would like to know if there is a way to add and subtract 1 second from a timestamp?  The results will be used in where clause to provide the upper and lower limits for a between... something like what you see below... which of course does not work:

select table2.char_column1, table2.timestamp_column2 from table1, table2 where table1.char_column = table2.char_column and table2.timestamp_column2 between dateadd(ss,-1,table1.timestamp_column2) and dateadd(ss,1,table1.timestamp_column2)

I need to use a timestamp range as a condition in the where clause to retrieve a specific row in table2.  The code above simply returns all of the rows from the second table. :(  

If someone can provide me with the correct syntax and a brief explanation as to why this code above does not work, I would appreciate it.  

Thank you all for your time...

gbclapsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ianmbCommented:
I presume the timestamp field in both tables is defined as datetime, and that table1.char_column & table2.char_column are a PK/FK pair? I've tried the same query on my installation  (Syb11.9.2) and it looks good. Can you show a subset of data from each table, with examples of which rows you want to see/filter?
gbclapsAuthor Commented:
The first table has the following row
 cusip     timestamp
 --------- --------------------------
 43233ACA2        Aug 27 2003  9:55AM

The second table contains the following rows...

 cusip     timestamp
 --------- --------------------------
 43233ACA2        Aug 13 2003  3:07PM
 43233ACA2        Aug 22 2003 11:54AM
 43233ACA2        Aug 22 2003 12:20PM
 43233ACA2        Aug 22 2003 12:21PM
 43233ACA2        Aug 25 2003 10:02AM
 43233ACA2        Aug 26 2003  9:11AM
 43233ACA2        Aug 27 2003  9:15AM
 43233ACA2        Aug 27 2003  9:55AM

The trick is that I must pick up the closest row from the second table that matches.  The logging process always posts within under a second... so I thought I should be able to put in a range of 2 seconds to ensure that I retrieve what I need.  My query returns all of the rows in table 2 when I really want just this one:

 cusip     timestamp
 --------- --------------------------
 43233ACA2        Aug 27 2003  9:55AM

Thanks.... :)
ianmbCommented:
I know this doesn't answer the question, but what happens if you do
select <blah>
where <blah>
and abs(datediff(ms, table1.timestamp, table2.timestamp)) < 1000  ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Sybase Database

From novice to tech pro — start learning today.