Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need your help to display correct data by date

Author  Topic 

hanhtn
Starting Member

2 Posts

Posted - 2011-07-27 : 08:01:59
Hi All

I have sql:
select * from tblCar
where TranDate >= '2011-06-09' and Trandate <= '2011-06-20'

CarID, CarType, TranDate, Type, Quantity
2563 BMW 2011-06-09 Hold -15 (1)
2563 BMW 2011-06-20 Return 15 (2)
2563 BMW 2011-06-20 Hold 20 (3)
.... ABC .....
.... IMF .....

And when I change the conditions of that sql as following:

select * from tblCar
where TranDate >= '2011-06-10' and Trandate <= '2011-06-19'
==> all the results was disappeared

Because you can know that a person borrow car 'BMW' from '2011-06-09' and until '2011-06-20' he returned it. So how can I keep the record (1) in the range date from '2011-06-09' to '2011-06-19'

Please help me.
Thanks you so much

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-27 : 08:41:10
we should know more about the relation between the rows via CarID and Type...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

hanhtn
Starting Member

2 Posts

Posted - 2011-07-27 : 10:50:23
Hi Webfred and All

Sorry, last time too briefly
This table should be like this: TBL_CAR_TX

TranID, AccID, CarID, TranDate, Type, Quantity, .....
--------------------------------------------------------
0 2563 BMW 2011-06-09 H -15
1 2563 BMW 2011-06-20 R 15
2 2563 BMW 2011-06-20 H 20
3 0055 TOY 2011-06-12 H -10
4 0055 TOY 2011-06-15 R 5
5 0055 TOY 2011-06-20 R 5
...
(H): Hold, (R): Release (don't have table for TYPE)

table TBL_CAR:
MarketID, CarID, Name, Size, ...
---------------------------
GER BMW
JPA TOY

Table TBL_PERSON:
AccID, Name, Age, DOB, ...
-------------------------
2563 Robert
0055 Mike

If you know please help me.
Thanksss
Go to Top of Page
   

- Advertisement -