Click here to Skip to main content
Rate this: bad
good
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 23:40pm
Edited 27-Mar-13 23:45pm
v2
Comments
OriginalGriff at 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
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 519
2 Maciej Los 305
3 BillWoodruff 250
4 Mathew Soji 195
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2014
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