Click here to Skip to main content
12,398,000 members (44,435 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL Server
hi

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

Using this format

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 27-Mar-13 22:40pm
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Have a look at your code:
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:
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?
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100