Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Syntaz 1

Status
Not open for further replies.

SQLneube

Technical User
Oct 6, 2005
5
US
Helppppp

I need to retrieve all the events that happened between June and December from a table(I don’t care about the year). What syntax would I use?


thanks
SQLNeubie
 
select * from dbo.table where
datepart(m,QueryDate) between 6 and 12

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
sorry, I need to retrieve the events that happens in 6 or 12 not between 6 and 12.

what syntax would I use
 
Something like this?

select * from dbo.table
where dateadd(m,6,QueryDate()) =getdate()
or
dateadd(m,12,QueryDate()) =getdate()


or is this what you are looking for??

select * from dbo.table where

QueryDate = dateadd(m,6,QueryDate())
or
QueryDate = dateadd(m,12,getdate())

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
Can I query like this -

select * from dbo.table
where datepart(mm,query_date)= 6 or
datePart(mm,query_date) = 12
and can I add this select statement as a subquery and how would I do that?

thanks
SQLNeube
 
When I tried the 2nd select statement...it returns that QueryDate()is not known.

What should I put in place of QueryDate?

Thanks
 
query_date would be the name of the datetime filed in your Table

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top