sql server programming:
Something like this should work for you:
SELECT
Emp_Name =3D FirstName + ' ' + LastName,
LastName,=20
HireDate,=20
Month =3D month( dateadd( month, -1, getdate() ))
FROM Employee
WHERE ( HireDate >=3D dateadd( month, ( datediff( month, 0, getdate() =
) -1), 0 )=20
AND HireDate < dateadd( month, datediff( month, 0, getdate() ), 0 =
)=20
)
--=20
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.=20
Most experience comes from bad judgment.=20
- Anonymous
You can't help someone get up a hill without getting a little closer to =
the top yourself.
- H. Norman Schwarzkopf
[quoted text, click to view] "zwieback89 via SQLMonster.com" <u28634@uwe> wrote in message =
news:690cbdd26f9af@uwe...
> Hi,
>=20
> How can I get all the hiredates which is falls in the previous month?
>=20
> Supposed today is November 9th. So I would like to take todays' date =
-
> GetDate()=20
>=20
> Now I want to find the previous month's hires.
>=20
> SELECT FirstName + ' ' + LastName AS Emp_Name, LastName, HireDate, =
MONTH
> (GETDATE()) - 1 AS Month
> FROM Employee
>=20
> I want to add a where clause where Hire date is between the 1st and =
last day
> of the previous month. How can I achieve this?
>=20
> Thanks.
>=20
> --=20
> ---------------------
> zwieback89
>=20
> Message posted via
http://www.sqlmonster.com
Try this -
SELECT FirstName + ' ' + LastName AS Emp_Name, LastName, HireDate, MONTH
(GETDATE()) - 1 AS Month
FROM Employee
WHERE HireDate BETWEEN DateAdd(d, - (Day(DateAdd(m, -1, GetDate())) - 1),
DateAdd(m, -1, GetDate())) AND DateAdd(d, - (Day(GetDate())), GetDate())
--
Ameet Phadnis
Sr. Technical Consultant
e Tek Global Inc.
ASP Alliance Author Page:
http://aspalliance.com/author.aspx?uId=44260 [quoted text, click to view] "zwieback89 via SQLMonster.com" wrote:
> Hi,
>
> How can I get all the hiredates which is falls in the previous month?
>
> Supposed today is November 9th. So I would like to take todays' date -
> GetDate()
>
> Now I want to find the previous month's hires.
>
> SELECT FirstName + ' ' + LastName AS Emp_Name, LastName, HireDate, MONTH
> (GETDATE()) - 1 AS Month
> FROM Employee
>
> I want to add a where clause where Hire date is between the 1st and last day
> of the previous month. How can I achieve this?
>
> Thanks.
>
> --
> ---------------------
> zwieback89
>
> Message posted via
http://www.sqlmonster.com >
Hi,
How can I get all the hiredates which is falls in the previous month?
Supposed today is November 9th. So I would like to take todays' date -
GetDate()
Now I want to find the previous month's hires.
SELECT FirstName + ' ' + LastName AS Emp_Name, LastName, HireDate, MONTH
(GETDATE()) - 1 AS Month
FROM Employee
I want to add a where clause where Hire date is between the 1st and last day
of the previous month. How can I achieve this?
Thanks.
--
---------------------
zwieback89
Message posted via
http://www.sqlmonster.com
[quoted text, click to view] zwieback89 via SQLMonster.com wrote:
> Hi,
>
> How can I get all the hiredates which is falls in the previous month?
>
> Supposed today is November 9th. So I would like to take todays' date -
> GetDate()
>
> Now I want to find the previous month's hires.
>
> SELECT FirstName + ' ' + LastName AS Emp_Name, LastName, HireDate, MONTH
> (GETDATE()) - 1 AS Month
> FROM Employee
>
> I want to add a where clause where Hire date is between the 1st and last day
> of the previous month. How can I achieve this?
>
> Thanks.
>
If your employee table isn't too large, you could simply do:
SELECT
FirstName + ' ' + LastName AS Emp_Name,
LastName,
HireDate,
MONTH(HireDate) AS Month
FROM Employee
WHERE DATEDIFF(month, HireDate, GETDATE()) = -1
This will do a table or index scan, so it might not be the best approach
for a large table...
--
Tracy McKibben
MCDBA
Don't see what you're looking for? Try a search.