December 26, 2006 at 1:21 pm
Fellow DBA's/Developers,
I'm trying to retrieve transactions that meet the criteria of (yyyy/mm/dd/ss) and eliminating milliseconds. The query below will retrieve the records that are equivalent up to milliseconds, but I just want the records that satisfy up to seconds. Please Help!!! Thanks in advance.... -Dave
SELECT
name_on_card_vc,Invoice_Id, trx_hd_key, Approval_Code_CH,
Date_DT, Trans_Type_ID ,total_amt_mn
FROM TrxDetailCard a
WHERE
Date_DT >= '20061101' and Date_DT < '20061223'
AND Trans_Type_ID = 'Sale'
and
Merchant_Key = 1291
and
exists
(
select 'x'
from TrxDetailCard b
where a.name_on_card_vc = b.name_on_card_vc
and a.Invoice_Id = b.Invoice_Id
and a.acct_num_ch = b.acct_num_ch
and a.Date_DT = b.Date_DT
and (a.trx_hd_key != b.trx_hd_key
OR a.Approval_Code_CH != b.Approval_Code_CH))
December 26, 2006 at 2:41 pm
Sample data and required output would be nice but here's a guess :
WHERE DateCol >= '1998-01-01 10:00:34' AND DateCol < '1998-01-01 23:59:57'
December 26, 2006 at 3:53 pm
Here's the sample data: '2006-12-06 10:26:27.170'
What I'd like to retrieve are the transactions that are in the following format: '2006-12-06 10:26:27'
Excluding milliseconds as shown in this datetime example. All records that meet the same date/timestamp without milliseconds.
December 26, 2006 at 4:57 pm
The data is kept in a varchar field or in a datetime field??
Also you can check out the convert function in books online.
December 27, 2006 at 6:47 am
and convert(varchar, a.Date_DT, 120) = convert(varchar, b.Date_DT, 120)
This will find two records if they are in the same second. It doesn't round.
Also, this method will mean that indexes won't be used.
Russel Loski, MCSE Business Intelligence, Data Platform
December 27, 2006 at 11:02 am
Thanks Russel! And thanks for everyone else's input also. It was a "datetime" field BTW. That's exactly what I'm looking for. I'll try it out. Much appreciated!
December 27, 2006 at 1:47 pm
BTW, my version will use an index seek (or won't forbid the use of). But either solution will return the correct data.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply