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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-12-16 : 09:25:16
|
| hakeem writes "Dear sir,I want to search the records between two dates. I have assigned varchar data type to the coloumn name..I have more than 2000 recores in my table..whenever the user inserts the data in a table the system date automatically stores in a table(mm/dd or d/yyyy format). When i use the query like this i am getting wrong results.select * from t1 where date1>=sdate and date1<=edate;So, please guide me in this matter.Thanks,Hakeem." |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-12-16 : 09:33:41
|
| Why not store the data as a datetime or smalldatetime?You are probably doing a character comparison rather than a date comparison here. Try converting everything to datetime.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-12-16 : 14:48:37
|
quote: Originally posted by AskSQLTeam mm/dd or d/yyyy format
Well which one though?And you then need to make assumptions#1 Assume current year?#2 Assume Current Month?What you're capturing will changing in meaning a time move forward...(or backward as the case may be...)Brett8-) |
 |
|
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2003-12-17 : 01:13:24
|
I guess he meant mm/d/yyyy format, which goes 12/8/2003, 12/9/2003, 12/10/2003, 12/11/2003...so you could say that is mm/(d or dd)/yyyy format Well, you could cast the value to datetime for such comparisions: CAST(myValue AS Datetime), but that would just be plain inefficient. Like Tara asks, why aren't you storing the values in a datetime column?OwaisWe make a living out of what we get, but we make a life out of what we give. |
 |
|
|
|
|
|