Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi

cccd    trdt
hit07   2007-01-08
hit07   2007-04-06
hit07   2007-04-06
hit07   2007-04-06


Using this format

SQL
declare @sal1 as int,@sal2 as int
set @sal1=1000
set @sal2=2500
select trdt as trdt from #tes where cccd='hit07' and CAST(trdt as datetime)
 between @stdt and @eddt


i need output

2007-01-08 00:00:00.000
2007-04-06 00:00:00.000
2007-04-06 00:00:00.000
2007-04-06 00:00:00.000


but this query not work.....

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 27-Mar-13 22:45pm
v2
Comments
OriginalGriff 28-Mar-13 4:46am    
How does it not work?
What does it do that it shouldn't or not do that it should?

1 solution

Have a look at your code:
SQL
declare @sal1 as int,@sal2 as int
set @sal1=1000
set @sal2=2500
select trdt as trdt from #tes where cccd='hit07' and CAST(trdt as datetime)
 between @stdt and @eddt


and for my, now:
SQL
DECLARE @stdt DATETIME
DECLARE eddt DATETIME

SET @stdt='2007-01-08'
SET @eddt='2007-03-31'

SELECT trdt 
FROM #tes
WHERE cccd='hit07' and trdt BETWEEN @stdt and @eddt


Do you see the difference?
 
Share this 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