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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server 2000 - Query Analyzer - Yearly Details

Status
Not open for further replies.

shivalisv

Technical User
Jan 13, 2004
9
IN
How could I get all the transactions which took place from the begining of the Year to Current date excluding current date and if the query is executed on Jan 1st of the year 2004 then all transactions of the previous whole year should be displayed and if the query is executed on March 14th 2004 then all transactions from Jan 1st till March 14th 2004 should be displayed excluding that current day.
 
Similar to the other query
Looks like I had varchar(4) in that one instead on varchar(6) to include the month.
For the year it is something like.

select *
from tbl
where tbl.trdte >= convert(varchar(4),dateadd(dd,-1,getdate()),112) + '0101' and tbl.trdte < convert(varchar(8),getdate(),112)

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top