|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, October 10, 2012 12:01 PM
Points: 2,
Visits: 1
|
|
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
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 9:48 AM
Points: 8,967,
Visits: 8,530
|
|
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 Moden's splitter.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 12:35 AM
Points: 835,
Visits: 616
|
|
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')
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, December 18, 2012 4:01 AM
Points: 13,
Visits: 37
|
|
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')
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 10:11 AM
Points: 1,333,
Visits: 1,803
|
|
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) One man with courage makes a majority. Andrew Jackson
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 10:11 AM
Points: 1,333,
Visits: 1,803
|
|
[Removed, duplicate post.]
SQL DBA,SQL Server MVP('07, '08, '09) One man with courage makes a majority. Andrew Jackson
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, October 10, 2012 12:01 PM
Points: 2,
Visits: 1
|
|
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!!
|
|
|
|