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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 ----- TSQL Newb Help ------

Author  Topic 

RAVSKINS
Starting Member

21 Posts

Posted - 2010-12-13 : 19:49:25
I'm adding some functionality to an already existing SQL - the current SQL is the following:

SELECT
REQ.Job_Number,
REQ.Request_Title AS Task_Title,
CONVERT(char(10),REQ.Date_Created,120) AS Date_Created,
MAX(CONVERT(char(10),Action_Time,120)) AS 'Date Sent for Release'
FROM
Request REQ
INNER JOIN Response R ON R.Request_ID = REQ.Request_ID
INNER JOIN Response_Action_History RAH ON RAH.Response_ID = R.Response_ID
INNER JOIN PersonnelS P ON P.ID = RAH.User_ID
WHERE
(R.Is_Released = 1 AND R.Date_Released BETWEEN '10/1/2005' AND '09/30/2009'
AND RAH.Response_Action_ID = 1
AND P.Level_Type_ID = '5A950A08-E023-4238-84C3-C27E281A7EDF'
AND P.Level_No_ID = 'B1BF80F1-E9DA-4D89-AD0E-4C223E5919D3')
AND RAH.Sent_to_ID = '911FE4CA-BC39-11D4-87EA-00B0D0785B6D'
GROUP BY
REQ.Job_Number,
REQ.Date_Created,
REQ.Request_Title
ORDER BY 1

1) I need to filter by more than one ID from my RESPONSE_ACTION_HISTORY table in my WHERE clause (in the red). So "WHERE RAH.Sent_To_ID IN ('ID', 'ID')." However, I'd rather filter it by Level_No_ID and Level_Type_ID from the PERSONNELS table, so that I don't have to update the query with additional ID's down the road, as new ones are added, or old ones replaced, but I'm already hitting those earlier in why WHERE clause. How would I search my RESPONSE_ACTION_HISTORY table for the Level_No_ID and Level_Type_ID of the sender, and well as the same thing for the Recipient?

2) How do I make a new column of returned values in my SELECT clause, for the first instance of an event. For instance, there will be multiple times that person A sends something to person B, but how do I only capture the first time that it occurs?

Not sure if I'm making total sense, but I'll be happy to try to clarify if possible. I appreciate the help!

RAVSKINS
Starting Member

21 Posts

Posted - 2010-12-14 : 12:22:05
quote:
Originally posted by RAVSKINS

I'm adding some functionality to an already existing SQL - the current SQL is the following:

SELECT
REQ.Job_Number,
REQ.Request_Title AS Task_Title,
CONVERT(char(10),REQ.Date_Created,120) AS Date_Created,
MAX(CONVERT(char(10),Action_Time,120)) AS 'Date Sent for Release'
FROM
Request REQ
INNER JOIN Response R ON R.Request_ID = REQ.Request_ID
INNER JOIN Response_Action_History RAH ON RAH.Response_ID = R.Response_ID
INNER JOIN PersonnelS P ON P.ID = RAH.User_ID
WHERE
(R.Is_Released = 1 AND R.Date_Released BETWEEN '10/1/2005' AND '09/30/2009'
AND RAH.Response_Action_ID = 1
AND P.Level_Type_ID = '5A950A08-E023-4238-84C3-C27E281A7EDF'
AND P.Level_No_ID = 'B1BF80F1-E9DA-4D89-AD0E-4C223E5919D3')
AND RAH.Sent_to_ID = '911FE4CA-BC39-11D4-87EA-00B0D0785B6D'
GROUP BY
REQ.Job_Number,
REQ.Date_Created,
REQ.Request_Title
ORDER BY 1

1) I need to filter by more than one ID from my RESPONSE_ACTION_HISTORY table in my WHERE clause (in the red). So "WHERE RAH.Sent_To_ID IN ('ID', 'ID')." However, I'd rather filter it by Level_No_ID and Level_Type_ID from the PERSONNELS table, so that I don't have to update the query with additional ID's down the road, as new ones are added, or old ones replaced, but I'm already hitting those earlier in why WHERE clause. How would I search my RESPONSE_ACTION_HISTORY table for the Level_No_ID and Level_Type_ID of the sender, and well as the same thing for the Recipient?

2) How do I make a new column of returned values in my SELECT clause, for the first instance of an event. For instance, there will be multiple times that person A sends something to person B, but how do I only capture the first time that it occurs?

Not sure if I'm making total sense, but I'll be happy to try to clarify if possible. I appreciate the help!


I know this won't work, but this is the direction I'm headed:

SELECT
REQ.Job_Number,
REQ.Request_Title AS Task_Title,
CONVERT(char(10),REQ.Date_Created,120) AS Date_Created,
MAX(CONVERT(char(10),Action_Time,120)) AS 'Date Sent for
Release'
MIN(CONVERT(char(10),Action_Time,120)) AS 'Date Sent From Initiator'
FROM
Request REQ
INNER JOIN Response R ON R.Request_ID = REQ.Request_ID
INNER JOIN Response_Action_History RAH ON RAH.Response_ID = R.Response_ID
INNER JOIN PersonnelS P ON P.ID = RAH.User_ID
WHERE
(R.Is_Released = 1 AND R.Date_Released BETWEEN '10/1/2005' AND '09/30/2009'
AND RAH.Response_Action_ID = 1
AND P.Level_Type_ID = '5A950A08-E023-4238-84C3-C27E281A7EDF'
AND P.Level_No_ID = 'B1BF80F1-E9DA-4D89-AD0E-4C223E5919D3')
AND (RAH.Sent_to_ID = P.Level_Type_ID = '725FBD2A-E284-491E-9E46-FF5E3FBC9C55'
AND RAH.Sent_to_ID = P.Level_No_ID = 'B1BF80F1-E9DA-4D89-AD0E-4C223E5919D3')

GROUP BY
REQ.Job_Number,
REQ.Date_Created,
REQ.Request_Title
ORDER BY 1


Does that clarify what I'm trying to do? I'm in fairly desperate need of some help here. Any direction you could give me would be HUGE. Thanks.....
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-12-14 : 13:33:43
I really would like to help you but I can't understand your needs.
You should give us:
CREATE statements of
Request
Response
Response_Action_History
PersonnelS

INSERT statements with sample data for each table

Wanted result in relation to the sample data.

I'm sure then someone here can give you a solution.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

RAVSKINS
Starting Member

21 Posts

Posted - 2010-12-15 : 10:44:28
quote:
Originally posted by webfred

I really would like to help you but I can't understand your needs.
You should give us:
CREATE statements of
Request
Response
Response_Action_History
PersonnelS

INSERT statements with sample data for each table

Wanted result in relation to the sample data.

I'm sure then someone here can give you a solution.


No, you're never too old to Yak'n'Roll if you're too young to die.



Okay - here are the related CREATE statements....

REQUEST:
CREATE TABLE [DB].[DBO].[Request] (
[Request_ID] uniqueidentifier NOT NULL,
[Segment_ID] uniqueidentifier NOT NULL,
[Request_Type_ID] uniqueidentifier NULL,
[Customer_ID] uniqueidentifier NOT NULL,
[WBS_Level_ID] uniqueidentifier NOT NULL,
[Parent_WBS1_ID] uniqueidentifier NULL,
[Parent_WBS2_ID] uniqueidentifier NULL,
[Actual_Date_Created] datetime NOT NULL,
[Date_Created] datetime NULL,
[Actual_Author_ID] uniqueidentifier NOT NULL,
[Author_ID] uniqueidentifier NULL,
[Owner_ID] uniqueidentifier NOT NULL,
[Previous_Owner_ID] uniqueidentifier NULL,
[Sent_From_ID] uniqueidentifier NULL,
[Sent_To_ID] uniqueidentifier NULL,
[Job_Number] varchar (155) NULL,
[Finalized] bit NOT NULL,
[Sent_For_Approval] bit NOT NULL,
[UserSegReceiver_ID] uniqueidentifier NULL,
[ApprovedBySegment] bit NOT NULL,
[RejectedBySegment] bit NOT NULL,
[Request_Title] varchar (100) NOT NULL,
[Revision_Number] varchar (4) NULL,
[Contract_Numbers_ID] uniqueidentifier NULL,
[Period_of_Perf_Start] datetime NULL,
[Period_of_Perf_End] datetime NULL,
[Funding_Number] varchar (50) NULL,
[WBS_Number] varchar (50) NULL,
[Originated_ID] uniqueidentifier NULL,
[Ceiling_Cost] money NULL,
[Deleted] bit NOT NULL,
[Seq_Number] smallint NOT NULL,
[Is_Latest] bit NOT NULL,
[DCN_Number] varchar (50) NULL,
[Emergency] bit NOT NULL,
[Routine] bit NOT NULL,
[Is_Title_Dirty] bit NOT NULL,
[ActivationDate] smalldatetime NULL,
[IDIQ] bit NULL,
[BuildingID] int NULL,
[CustomerBusinessEntityID] uniqueidentifier NULL,
[ServiceTypeID] int NULL,
[Disclaimer] varchar (2000) NULL,
[PerformanceMonitoring] text NULL,
[ExternalId] varchar (36) NULL,
[FundingWBS] varchar (20) NULL,
[CostCenter] varchar (20) NULL)

RESPONSE:
CREATE TABLE [DB].[DBO].[Response] (
[Response_ID] uniqueidentifier NOT NULL,
[Request_ID] uniqueidentifier NULL,
[Revision_No] char (10) NULL,
[Owner_ID] uniqueidentifier NULL,
[Sent_To_ID] uniqueidentifier NULL,
[Role_ID] int NULL,
[Send_To_Role_ID] int NULL,
[Lead_ID] uniqueidentifier NULL,
[Technical1_ID] uniqueidentifier NULL,
[Technical2_ID] uniqueidentifier NULL,
[Originator_ID] uniqueidentifier NULL,
[Business_Office_Rep_ID] uniqueidentifier NULL,
[Approval1_ID] uniqueidentifier NULL,
[Approval2_ID] uniqueidentifier NULL,
[Approval3_ID] uniqueidentifier NULL,
[Approval4_ID] uniqueidentifier NULL,
[Approval5_ID] uniqueidentifier NULL,
[Is_Released] bit NULL,
[Are_Members_Dirty] bit NULL,
[Date_Created] datetime NULL,
[OCI] bit NULL,
[Is_Schedule_Dirty] bit NOT NULL,
[Is_PDF_Changed] bit NOT NULL,
[Is_Revisable] bit NOT NULL,
[Date_Released] datetime NULL,
[Estimate_Amt] money NULL,
[Approval6_ID] uniqueidentifier NULL,
[Approval7_ID] uniqueidentifier NULL,
[Approval8_ID] uniqueidentifier NULL,
[Approval9_ID] uniqueidentifier NULL,
[Approval10_ID] uniqueidentifier NULL,
[Cost_Estimated_Date] datetime NULL,
[EstimateStartDate] smalldatetime NULL,
[EstimateEndDate] smalldatetime NULL,
[OvertimeRate] int NULL,
[ProjectedHours] float NULL,
[ProjectedDollars] money NULL,
[FTE] money NULL,
[SupportStaffHrs] decimal (12,6) NULL,
[FundingRunOutHoursDate] smalldatetime NULL,
[FundingRunOutDollarsDate] smalldatetime NULL,
[ActualsPeriod] int NULL,
[Type] smallint NULL,
[Justification] varchar (50) NULL,
[EstimateAmount] decimal (18,2) NULL,
[CustomerFunding] smallint NULL,
[CardHolderName] varchar (50) NULL,
[CardNumber] varchar (16) NULL,
[ExpirationDate] varchar (50) NULL,
[CardFundingAmount] money NULL,
[PurchaseRequestNum] varchar (16) NULL,
[FundingNote] varchar (50) NULL,
[Approval32_ID] uniqueidentifier NULL,
[Approval11_ID] uniqueidentifier NULL,
[SOW] text NULL,
[PerformanceMeasurement] text NULL,
[ProposalEstimateID] uniqueidentifier NULL,
[AnalystID] uniqueidentifier NULL)

RESPONSE_ACTION_HISTORY:
CREATE TABLE [DB].[DBO].[Response_Action_History] (
[Response_Action_History_ID] uniqueidentifier NOT NULL,
[Response_ID] uniqueidentifier NULL,
[Response_Action_ID] int NULL,
[User_ID] uniqueidentifier NULL,
[Action_Time] datetime NULL,
[Action_Comment] varchar (1000) NULL,
[Sent_To_ID] uniqueidentifier NULL)

PERSONNELS:
CREATE TABLE [DB].[DBO].[PersonnelS] (
[Id] uniqueidentifier NOT NULL,
[UserName] varchar (20) NULL,
[Password] varchar (30) NULL,
[SID] varchar (50) NULL,
[LastName] varchar (30) NOT NULL,
[FirstName] varchar (20) NOT NULL,
[MiddleName] varchar (20) NULL,
[Nickname] varchar (50) NULL,
[WorkPhone] varchar (24) NULL,
[DeskPhone] varchar (24) NULL,
[JobCode] varchar (6) NULL,
[JobCodeTitle] varchar (30) NULL,
[JobCodeDate] smalldatetime NULL,
[WorkmanCompCode] varchar (15) NULL,
[PayFrequency] char (1) NULL,
[TempPermFlag] char (1) NULL,
[HireDate] smalldatetime NULL,
[TerminationDate] smalldatetime NULL,
[SupervisorNo] varchar (11) NULL,
[Email] varchar (50) NULL,
[ExternalId1] varchar (20) NULL,
[ExternalId2] varchar (20) NULL,
[StateTaxCode] char (2) NULL,
[SSN] int NULL,
[LastUpdated] datetime NOT NULL,
[IsTerminated] bit NULL,
[IsLocked] bit NULL,
[LastLogin] smalldatetime NULL,
[LastPasswordChange] smalldatetime NOT NULL,
[EmergencyContact] varchar (50) NULL,
[EmergencyPhone] varchar (24) NULL,
[EmergencyRelation] varchar (10) NULL,
[Level_No_Id] uniqueidentifier NULL,
[Level_Type_id] uniqueidentifier NULL,
[Is_Business_Office_Rep] bit NULL,
[Is_Approver] bit NULL,
[OrganizationId] int NULL,
[BuildingCode] varchar (12) NULL,
[RoomNum] varchar (12) NULL,
[Tier2Approver] bit NULL,
[MailCode] varchar (20) NULL,
[Suffix] varchar (10) NULL,
[Title] varchar (10) NULL,
[Citizenship_Country] char (3) NULL,
[Citizenship_Status] char (1) NULL,
[Citizenship_Descr] char (30) NULL,
[PagerNo] char (24) NULL,
[Address1] char (30) NULL,
[City] char (20) NULL,
[State] char (2) NULL,
[ZipCodeMain] char (5) NULL,
[ZipCodeSub] char (4) NULL)

Go to Top of Page
   

- Advertisement -