| Author |
Topic |
|
Dajope
Starting Member
6 Posts |
Posted - 2007-02-21 : 00:21:06
|
| hey all.I'm VERY new to SQL and this is throwing me a tad...I want to do the followingSELECT T1.ID, T1.NoFROM MYDB.DB.T1 T1WHERE T1.No = TODAYi only want to return the values that equal No being today.am i on the right track? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-21 : 00:28:06
|
colunn T1.No is datetime ?SELECT T1.ID, T1.NoFROM MYDB.DB.T1 T1WHERE T1.No = TODAY dateadd(day, datediff(day, 0, getdate()), 0) KH |
 |
|
|
Dajope
Starting Member
6 Posts |
Posted - 2007-02-21 : 00:34:51
|
| Cheers KH,the only problem is the No field is date and time, however i only want to return the data if it is TODAY, not today between a specific time.any ideas? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-21 : 00:40:56
|
[code]SELECT T1.ID, T1.NoFROM MYDB.DB.T1 T1WHERE T1.No >= dateadd(day, datediff(day, 0, getdate()), 0) -- greater or equal to todayand T1.No < dateadd(day, datediff(day, 0, getdate()), 1) -- less than tomorrow[/code] KH |
 |
|
|
Dajope
Starting Member
6 Posts |
Posted - 2007-02-21 : 00:48:19
|
| whoa!! Microsoft Query didn't like that crashed it ha.!! thanks for the help!! |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-21 : 00:49:50
|
try removing comments after and including the "--".what is the error message ? KH |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-21 : 00:59:53
|
quote: Originally posted by Dajope whoa!! Microsoft Query didn't like that crashed it ha.!! thanks for the help!!
Microsoft Query from Excel ?Try edit the SQL Query and remove the '#' sign KH |
 |
|
|
Dajope
Starting Member
6 Posts |
Posted - 2007-02-21 : 01:02:02
|
| all good now.. kinda. I've added another table to return more values, although it is returning everything i want, 100 times!!thanks :) |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-21 : 01:05:26
|
you did not specify the join condition ?SELECT T1.ID, T1.NoFROM MYDB.DB.T1 T1 INNER JOIN MYDB.DB.T2 T2ON T1.ID = T2.IDWHERE . . . KH |
 |
|
|
Dajope
Starting Member
6 Posts |
Posted - 2007-02-21 : 01:12:13
|
| it returns all relevant fields etc.there are 3 items that are relevant and that should be shown,but those 3 items are shown over, and over, and over etc. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-21 : 01:14:26
|
| Try to include a DISTINCT directly after the SELECT...Peter LarssonHelsingborg, Sweden |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-21 : 01:23:22
|
Please post the query here KH |
 |
|
|
|