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 |
Edward M
Starting Member
2 Posts |
Posted - 2009-03-08 : 18:01:45
|
Hi I'm fairly new to writing SQL queries and could do with some advice. I have a table called booking in which there is a row called date.I want to write a query that when a user enters 14/02/09 for example it pulls up every entry on that day.I triedSELECT * FROM BookingWHERE Date LIKE @Date + '%'but that gives me a error stating it cant match the dateTime to a varChar2. I have searched the net for examples but can't seem to find what I need, can anyone help at all?Thanks |
|
hey001us
Posting Yak Master
185 Posts |
Posted - 2009-03-08 : 20:28:26
|
SET @Date = '14/02/09'I assume the date field is Date Time Data type. Try this!SELECT * FROM BookingWHERE Date between @Date + '00:00:00' and @Date + '23:59:59'hey |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-03-09 : 05:47:46
|
More effecientSELECT * FROM BookingWHERE Date >=@Date and Date<dateadd(day,1,@date)MadhivananFailing to plan is Planning to fail |
|
|
Edward M
Starting Member
2 Posts |
Posted - 2009-03-10 : 08:28:27
|
Great, Thanks for the help on this, really appreciate help. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-03-10 : 08:32:41
|
quote: Originally posted by Edward M Great, Thanks for the help on this, really appreciate help.
You are welcome Let me know which one you have decided to useMadhivananFailing to plan is Planning to fail |
|
|
GustiX
Starting Member
28 Posts |
Posted - 2009-03-13 : 11:57:09
|
HiYou might also try to cast the @Date variable to date. SQL Server 2008 has a date datatypeSELECT *FROM BookingWHERE Date = cast(@Date as date) |
|
|
|
|
|