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 |
wkm1925
Posting Yak Master
207 Posts |
Posted - 2008-05-10 : 11:06:57
|
i've these following table,tblSELDate_Taken |Time |Main_ID------------------------------------------4/3/2005 12:00:00 AM | 1148 | 2334/3/2005 12:00:00 AM | 1248 | 2314/3/2005 12:00:00 AM | 1348 | 2354/3/2005 12:00:00 AM | 1448 | 2324/3/2005 12:00:00 AM | 1548 | 2234/3/2005 12:00:00 AM | 1648 | 245tblMainID_DescMain_ID | Location-------------------233 | PRK235 | WP245 | PER......Let's say current date is 3 APRIL 2005i run following querySELECTt1.Date_Taken, t1.Time,t1.Main_IDFROM dbo.SEL t1 INNER JOIN dbo.station_info t2ON t1.Main_ID=t2.Main_IDWHERE t2.Location='PRK' AND t1.Date_Taken=CONVERT(VARCHAR(10), GETDATE(), 101)ORDER BY t1.Date_Taken, t1.Timethen, result shown as followtblResultDate_Taken |Time |Main_ID---------------------------------------2005-04-03 00:00:00 |0 |2342005-04-03 00:00:00 |2 |236.........Why Date_Taken different from tblSEL above? How to setting it to make sure nothing changes on Date_Taken when queries runned. |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-05-10 : 11:24:52
|
Is the data type for Date_Taken is Datetime? How and where do you see the first output?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
wkm1925
Posting Yak Master
207 Posts |
Posted - 2008-05-10 : 11:56:25
|
correction, my query isSELECTt1.Date_Taken, t1.Time,t1.Main_IDFROM dbo.tblSEL t1 INNER JOIN dbo.tblMainID_Desc t2ON t1.Main_ID=t2.Main_IDWHERE t2.Location='PRK' AND t1.Date_Taken=CONVERT(VARCHAR(10), GETDATE(), 101)ORDER BY t1.Date_Taken, t1.TimeDate_Taken is smalldatetime. I'm just open tblSEL using right click. |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-05-10 : 12:21:18
|
The date values are not changing. You seem be troubled by the presentation/formatting of the smalldatetime value. You should control the formatting of the datetime value in your presentation layer.When you INSERT a value into a smalldatetime column, sql server will implicitly CONVERTs many different strings into a smalldatetime value. These STRINGs will all be stored as the same smalldatetime value'2005-04-03 00:00:00''4/3/2005 12:00:00 AM''4/3/2005''2005-04-03'Internally sql server stores these values as a pair of SMALLINTs (no formatting is associated with the stored value)When you SELECT the values sql server uses the formatting defined by your server settings. You should be controlling the presentation of the values in whatever application presents the data. You can CONVERT the value to varchar and use any of the pre-defined formats available for converting datetime to varchar (see CONVERT). But if you do that you loose ability to manipulate, order, and calculate the values as dates so again, you should use the presentation layer to worry about the format.Be One with the OptimizerTG |
|
|
wkm1925
Posting Yak Master
207 Posts |
Posted - 2008-05-10 : 19:59:38
|
DO you have any sample in SQL to display '4/3/2005 12:00:00 AM' in Date Taken column? |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-11 : 13:07:41
|
Read about the CONVERT function in books online:-http://doc.ddart.net/mssql/sql70/ca-co_1.htm |
|
|
wkm1925
Posting Yak Master
207 Posts |
Posted - 2008-05-12 : 03:36:56
|
tq to mr. harsh_athalye, mr. TG and mr. visakh16. |
|
|
|
|
|
|
|