Click here to Skip to main content
15,906,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am joining two tables in table1 using TMAST_DATE column i am selecting that column date should not give the result i am using below code please help any one

SQL
select IR.TMAST_DESCRIPTION,IR.TMAST_QUANTITY_ISSUED,TM.TMAST_QTY from INSERTREPORT as IR
 inner join
TMAST as TM on  IR.TMAST_BIN_NO=TM.TMAST_BIN_NO
where IR.TMAST_DATE=11/11/2013 and IR.TMAST_DATE=31/12/2013
Posted
Updated 29-Dec-13 19:19pm
v2

This works:

SQL
create table test
(
 id int identity,
 dt datetime

)

 insert into test values (getdate()),(getdate()),(getdate()),(getdate()),(getdate()),(getdate()),(getdate()),(getdate()),(getdate()),(getdate()),(getdate())


select * from test where dt between '2013/12/30' and '2014/01/01'



You should NEVER convert date times to strings to convert them, that's asking the DB to work for no reason. You should always specify dates a YYYY/MM/DD because that works the same on any SQL Server, unlike dd/mm/yyyy or mm/dd/yyyy.

So, to fix your SQL:

SQL
select IR.TMAST_DESCRIPTION,IR.TMAST_QUANTITY_ISSUED,TM.TMAST_QTY from INSERTREPORT as IR
 inner join
TMAST as TM on  IR.TMAST_BIN_NO=TM.TMAST_BIN_NO
where IR.TMAST_DATE >= '2013/11/11' and IR.TMAST_DATE <='2013/12/31'
 
Share this answer
 
v2
try this:-
SQL
select IR.TMAST_DESCRIPTION,IR.TMAST_QUANTITY_ISSUED,TM.TMAST_QTY from INSERTREPORT as IR
inner join
TMAST as TM on IR.TMAST_BIN_NO=TM.TMAST_BIN_NO
where  CONVERT(datetime, a.start_dateTime, 101) BETWEEN '2013-11-11' and '2013-12-31'
 
Share this answer
 
Comments
Christian Graus 30-Dec-13 3:04am    
Again, why can't you do this with dates instead of strings ?
SQL
select IR.TMAST_DESCRIPTION,IR.TMAST_QUANTITY_ISSUED,TM.TMAST_QTY from INSERTREPORT as IR
 inner join
TMAST as TM on  IR.TMAST_BIN_NO=TM.TMAST_BIN_NO
where Convert(varchar(10),IR.TMAST_DATE,101) between '11/11/2013' and '31/12/2013'
 
Share this answer
 
Comments
Christian Graus 30-Dec-13 3:03am    
Horrible. Why would you convert to a string, to slow it down ?
coded007 30-Dec-13 4:12am    
ok
where IR.TMAST_DATE between '11/11/2013' and '31/12/2013'

Replace your last statement with the above statement...

Your problem will be solved..
 
Share this answer
 
Comments
Christian Graus 30-Dec-13 3:04am    
Weird that this got a one, it;s the best answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900