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 2000 Forums
 SQL Server Development (2000)
 Query help

Author  Topic 

zubairmasoodi
Starting Member

35 Posts

Posted - 2007-05-15 : 01:42:49
hi

SELECT * FROM aS_tblPresentations
WHERE CONVERT(VARCHAR,CreatedDateTime,101) BETWEEN CONVERT(VARCHAR,'10/3/2006',101) AND CONVERT(VARCHAR,'5/15/2007',101)


The above query Returns me 0 results from my database even though the
table contains hundreds of records in the specified data range

what is the reason, where i am doing wrong ?

Thanks


With regards
Zubair Masoodi
(Every day's a school day)

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-15 : 01:50:54
[code]where dateadd(day, 0, datediff(day, 0, CreatedDateTime)) betweeen '20061003' and '20070515'[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-15 : 04:18:08
www.sql-server-performance.com/fk_datetime.asp for more info on how to query on dates

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-15 : 06:16:09
where CreatedDateTime >= '20061003' and CreatedDateTime < '20070516'


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

zubairmasoodi
Starting Member

35 Posts

Posted - 2007-05-15 : 08:38:52
i appreciate ur responses But i want to know

what is the reason, where i am doing wrong ?

Thanks

With regards
Zubair Masoodi
(Every day's a school day)

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-15 : 08:51:33
Run the following query and see the result

SELECT CONVERT(VARCHAR, CreatedDateTime, 101),
case when CONVERT(VARCHAR, CreatedDateTime, 101) >= '10/3/2006' then '>= 10/03.2006' else '' end,
case when CONVERT(VARCHAR, CreatedDateTime, 101) <= '5/15/2007' then '<= 5/15/2007' else '' end
FROM aS_tblPresentations






KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-15 : 09:00:56
Also read the link I posted

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

zubairmasoodi
Starting Member

35 Posts

Posted - 2007-05-15 : 09:06:41

The First Case returns '' empty column, means

No date in my Table is greater than '10/3/2006'.

but honestly i am still saying the problem is not yet clear to me

why its happening ?
below is sample data

Createdatetime
03/29/2007 <= 5/15/2007
03/22/2007 <= 5/15/2007
03/22/2007 <= 5/15/2007
03/22/2007 <= 5/15/2007
03/23/2007 <= 5/15/2007
03/23/2007 <= 5/15/2007
03/23/2007 <= 5/15/2007

Thanks


With regards
Zubair Masoodi
(Every day's a school day)

Go to Top of Page
   

- Advertisement -