October 9, 2012 at 12:35 pm
Hi! I am trying to select records between July 1st 2011 and August 14, 2011. I am not returning any rows at all. I have searched and tried a few different things but nothing is working.
My SQL:
select *
from [Assessor_Forms].[dbo].[tblRental]
where TransactionDateStamp >= convert(datetime, '07/01/2011')
and TransactionDateStamp < convert(datetime, '08/15/2011')
Please let me know what I need to do differently.
Thanks!
MJ
October 9, 2012 at 12:59 pm
maryjane9110024 (10/9/2012)
Hi! I am trying to select records between July 1st 2011 and August 14, 2011. I am not returning any rows at all. I have searched and tried a few different things but nothing is working.My SQL:
select *
from [Assessor_Forms].[dbo].[tblRental]
where TransactionDateStamp >= convert(datetime, '07/01/2011')
and TransactionDateStamp < convert(datetime, '08/15/2011')
Please let me know what I need to do differently.
Thanks!
MJ
What datatype is TransactionDateStamp? If it is datetime there is no need for the convert.
where TransactionDateStamp > '20110701'
and TransactionDateStamp < '20110815'
If you have your string as yyyymmdd it will work implicitly casting to a datetime regardless of the dateformat settings of the server.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 9, 2012 at 11:54 pm
Pls check conditions...
DECLARE @T TABLE (ID INT,DAT DATETIME)
INSERT INTO @T(ID,DAT)
SELECT 1,'2012-04-01 10:20:00'
UNION
SELECT 1,'2012-05-01 10:20:00'
UNION
SELECT 1,'2012-06-01 10:20:00'
SELECT * FROM @T
WHERE DAT >= convert(datetime, '04/01/2012')
and DAT < convert(datetime, '06/15/2012')
October 10, 2012 at 4:32 am
My SQL:
select *
from [Assessor_Forms].[dbo].[tblRental]
where TransactionDateStamp >= convert(datetime, '07/01/2011')
and TransactionDateStamp < convert(datetime, '08/15/2011')
Hello Try This,
select *
from [Assessor_Forms].[dbo].[tblRental]
where TransactionDateStamp >= convert(date, '07/01/2011')
and TransactionDateStamp < convert(date, '08/15/2011')
October 10, 2012 at 11:16 am
Sean Lange (10/9/2012)
maryjane9110024 (10/9/2012)
Hi! I am trying to select records between July 1st 2011 and August 14, 2011. I am not returning any rows at all. I have searched and tried a few different things but nothing is working.My SQL:
select *
from [Assessor_Forms].[dbo].[tblRental]
where TransactionDateStamp >= convert(datetime, '07/01/2011')
and TransactionDateStamp < convert(datetime, '08/15/2011')
Please let me know what I need to do differently.
Thanks!
MJ
What datatype is TransactionDateStamp? If it is datetime there is no need for the convert.
where TransactionDateStamp > '20110701'
and TransactionDateStamp < '20110815'
If you have your string as yyyymmdd it will work implicitly casting to a datetime regardless of the dateformat settings of the server.
True overall, but the first condition should still be >=, not just > :-).
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
October 10, 2012 at 11:18 am
[Removed, duplicate post.]
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
October 10, 2012 at 12:03 pm
Hi! Thank you for all the responses and help!! I figured out why it wasn't returning anything. There was no data to return. (duh me)
It was a datetime field and thank you on the info about not needing to convert it. I did not know that!
Thanks everyone!! 🙂
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply