SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 updating statement with incorrect dates.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masterdineen
Aged Yak Warrior

United Kingdom
549 Posts

Posted - 06/03/2013 :  17:29:23  Show Profile  Reply with Quote
Hello there. I have the following update statement

with cte_Trans

as (

select transactionid, purchaseID, MIN(convert(date,TransactionPurchaseDate)) as 'TransactionPurchaseDate'
from dbo.Ticket_History
where TransactionMOP <> 0
------------and BookingID = 542066
group by transactionid, purchaseID )

update t
set t.TransactionSoldDate = convert(date,Trans.TransactionPurchaseDate)
from dbo.Ticket_Facts t inner join cte_trans trans on
t.transactionid = trans.TransactionID


when I select * tickets from our ticket table with
where bookingid = 542066

then I get the following

transactionpurchasedate TransactionSoldDate
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-04-30
2013-05-01 2013-05-01
2013-05-01 2013-05-01
2013-05-01 2013-05-01


see the date that is 2013-04-30 when it should be 2013-05-01

what sort of things would cause this,

BUT if I run the update statement with a criteria of

where bookingid = 542066 then I don't get any problem.

very strange,

Regards

Rob

James K
Flowing Fount of Yak Knowledge

3744 Posts

Posted - 06/03/2013 :  17:42:18  Show Profile  Reply with Quote
Perhaps you have more than one booking id for a TransactionID and purchaseID combination? It's a wild guess, but you can check if that is so using this query. If it returns any rows at all, then you do:
with cte_Trans

as (

select transactionid, purchaseID, bookingID,
MIN(convert(date,TransactionPurchaseDate)) as 'TransactionPurchaseDate'
from dbo.Ticket_History
where TransactionMOP <> 0
------------and BookingID = 542066
group by transactionid, purchaseID , bookingID) 
SELECT transactionid, purchaseID, COUNT(*)
FROM cte_Trans GROUP BY transactionid, purchaseID 
HAVING COUNT(*) > 1
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000