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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 TODAY??

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 following

SELECT T1.ID, T1.No
FROM MYDB.DB.T1 T1
WHERE T1.No = TODAY

i 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.No
FROM MYDB.DB.T1 T1
WHERE T1.No = TODAY dateadd(day, datediff(day, 0, getdate()), 0)



KH

Go to Top of Page

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?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-21 : 00:40:56
[code]
SELECT T1.ID, T1.No
FROM MYDB.DB.T1 T1
WHERE T1.No >= dateadd(day, datediff(day, 0, getdate()), 0) -- greater or equal to today
and T1.No < dateadd(day, datediff(day, 0, getdate()), 1) -- less than tomorrow
[/code]


KH

Go to Top of Page

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!!
Go to Top of Page

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

Go to Top of Page

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

Go to Top of Page

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 :)
Go to Top of Page

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.No
FROM MYDB.DB.T1 T1 INNER JOIN MYDB.DB.T2 T2
ON T1.ID = T2.ID
WHERE . . .



KH

Go to Top of Page

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.
Go to Top of Page

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 Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-21 : 01:23:22
Please post the query here


KH

Go to Top of Page
   

- Advertisement -