October 13, 2009 at 6:50 am
Good morning all,
I need to return values for monthly results over a 12 month period:
Employees Name Date of Hire Results for May 2008
John Doe 1994-10-14 20
USE bloodLeads
SELECT E.NAME, Pb As May2008, EmployeesBL.DOH, bloodLeadQry.Date
FROM EmployeesBL E
join bloodLeadQry on EmployeesBL.NAME = bloodLeadQry.NAME
WHEre bloodLeadQry.Date LIKE '2008-06-%'
This returns results for one month but I need results for 12 months.
Thanks in advance,
DJ Khalif
October 13, 2009 at 6:53 am
Hi!
I'd love to help you, can you post the create table statements for the tables you will be using with this query? I've posted what I feel is a correct result, try it and see if it works, if it's not what you're looking for post the create tables statement, and I'll see what I can do.
Thanks,
Bradley Jacques
USE bloodLeads
GO
SELECT E.NAME, Pb As May2008, EmployeesBL.DOH, bloodLeadQry.Date
FROM EmployeesBL E
join bloodLeadQry
on EmployeesBL.NAME = bloodLeadQry.NAME
Where bloodLeadQry.Date between to_date ('2008/01/01', 'yyyy/mm/dd')
AND to_date ('2008/12/31', 'yyyy/mm/dd');
October 13, 2009 at 7:11 am
What I need is, a column for each month.
USE bloodLeads
CREATe table MayResults
(
ResultID int IDENTITY (1,1) Primary Key NOT NULL,
NAME nvarchar(255) NOT NULL,
May2008 int NOT NUll,
DOH nvarchar(50),
Date nvarchar(50)
)
SELECT EmployeesBL.NAME, Pb As May2008, EmployeesBL.DOH, bloodLeadQry.Date
FROM EmployeesBL
join bloodLeadQry on EmployeesBL.NAME = bloodLeadQry.NAME
WHEre bloodLeadQry.Date LIKE '2008-05-%';
October 13, 2009 at 9:02 am
Can you post the CREATE statement for the tables referenced in the query? Just right click on the table in management studio and click SCRIPT TABLE AS->CREATE TO-> New Query Window then paste the tables here.
Thanks,
Bradley Jacques
October 13, 2009 at 9:46 am
USE [bloodLeads]
GO
/****** Object: Table [dbo].[bloodLeadQry] Script Date: 10/13/2009 11:43:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[bloodLeadQry](
[NAME] [nvarchar](255) NULL,
[DEPARTMENT] [nvarchar](255) NULL,
[DOH] [nvarchar](50) NULL,
[DATE] [nvarchar](50) NULL,
[Pb] [int] NULL
) ON [PRIMARY]
October 13, 2009 at 10:29 am
Bradley Jacques (10/13/2009)
Hi!I'd love to help you, can you post the create table statements for the tables you will be using with this query? I've posted what I feel is a correct result, try it and see if it works, if it's not what you're looking for post the create tables statement, and I'll see what I can do.
Thanks,
Bradley Jacques
USE bloodLeads
GO
SELECT E.NAME, Pb As May2008, EmployeesBL.DOH, bloodLeadQry.Date
FROM EmployeesBL E
join bloodLeadQry
on EmployeesBL.NAME = bloodLeadQry.NAME
Where bloodLeadQry.Date between to_date ('2008/01/01', 'yyyy/mm/dd')
AND to_date ('2008/12/31', 'yyyy/mm/dd');
Since this is a SQL Server 2005 forum, it would be better if you posted SQL Server syntax, instead of Oracle syntax.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply