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 |
|
ASP_DRUG_DEALER
Yak Posting Veteran
61 Posts |
Posted - 2004-05-24 : 14:58:23
|
| Hey all-I have a field defined as char(6) that stores the year and month(200405). I need to do a query that gets stuff from the previous year.Here is my quick hack that did not work...WHERE E_MASTER.EO_YEARMONTH Like (CONVERT CHAR(6),(CONVERT INT,((Left(@inYEARMONTH,4))-1)))someone enters what year and month they want totals for and it automaticly computes current year and also previous years. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-05-24 : 15:06:17
|
| WHERE ... CONVERT(CHAR(4), SUBSTRING(Column1, 1, 4) - 1) + SUBSTRING(Column1, 5, 2)Why not store the data in datetime format so that you can use datetime functions?Tara |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-05-24 : 16:32:45
|
| [code]DECLARE @x char(6), @y datetimeSELECT @x = '200405'SELECT @y = CONVERT(datetime,SUBSTRING(@x,1,4)+'/01/'+SUBSTRING(@x,5,2))SELECT @y, DATEADD(yy,-1,@y)[/code]Brett8-) |
 |
|
|
vganesh76
Yak Posting Veteran
64 Posts |
Posted - 2004-05-25 : 08:14:21
|
| WHERE ... stuff(@yearmonth,4,1,substring(@yearmonth,4,1) - 1)u can try this alsoGaneshEnjoy working |
 |
|
|
|
|
|
|
|