I am entering info into a timesheet table. The Client_PK_ID comes from the ClientBasicInfo table; the StepNumber_PK_ID and other info comes from the Jobs_JobSteps table. All the info gets inserted into the Timesheet table. Pretty basic idea.
I have the following Select statements.
Both pull the desired info correctly. My Insert is as follows:
In my results, I get 4 return lines:
And the message:
If the Client_PK_ID, the StepNumber_PK_ID and other info is correct, then why am I getting NULLS, a -6 return value and a msg telling me about a NULL Client_PK_ID?
I thought maybe the UNION would work, but I don't think that it is appropriate for this task.
Thanks,
Bill
I have the following Select statements.
Code:
SELECT Client_PK_ID
FROM tbl_Clients_ClientBasicInfo
WHERE
tbl_Clients_ClientBasicInfo.ClientNumber = @ClientNumber
---new select statement, same Sproc
SELECT StepNumber_PK_ID, PayFormulaCode AS PFC,
PrevailingWage AS PW, Standard AS STD
FROM
tbl_Jobs_JobSteps
JOIN
tbl_Jobs_JobNumber
ON
tbl_Jobs_JobSteps.JobNumber_PK_ID =
tbl_Jobs_JobNumber.JobNumber_PK_ID
JOIN
tbl_Customers_CustomerBasicInfo
ON
tbl_Jobs_JobNumber.Customer_PK_ID =
tbl_Customers_CustomerBasicInfo.Customer_PK_ID
JOIN
tbl_Jobs_JobStepCodesAndPayFormulaCodes
ON
tbl_Jobs_JobStepCodesAndPayFormulaCodes.StepCode =
tbl_Jobs_JobSteps.StepCode
where
tbl_Customers_CustomerBasicInfo.CustomerNumber = @CustomerNumber
and
tbl_Jobs_JobNumber.JobNumber = @JobNumber
and
tbl_Jobs_JobSteps.StepNumber = @StepNumber
and
tbl_Jobs_JobNumber.LocationNumber = @LocationNumber
Both pull the desired info correctly. My Insert is as follows:
Code:
if @Timesheet_PK_ID is null or
@TimeSheet_PK_ID = 0
begin
Insert into tbl_TimeSheetEntry
(BatchNumber,
LocationNumber,
WorkDate,
Client_PK_ID,
StepNumber_PK_ID,
--ClientTimeStudy_PK_ID,
HoursWorked,
Units,
PrevailingWage,
Standard,
WagesPaid,
FundingCode,
PayFormulaCode)
values
(@BatchNumber,
@LocationNumber,
@WorkDate,
@Client_PK_ID,
@StepNumber_PK_ID,
--@ClientTimeStudy_PK_ID,
@HoursWorked,
@Units,
@PrevailingWage,
@Standard,
@WagesPaid,
@FundingCode,
@PayFormulaCode
)
--Assign New TimeSheet_PK_ID to record just added
Set @TimeSheet_PK_ID = Scope_Identity ()
end
In my results, I get 4 return lines:
Code:
Client_PK_ID
3 --this is a valid #
StepNumber_PK_ID PFC PW Std
104 AW NULL NULL
--all of the above are valid #’s, but the following gives me NULLs
@Client_ @StepNumber_ @TimeSheet_ @Message
PK_ID PK_ID PK_ID
NULL NULL NULL
ReturnValue
-6
And the message:
Code:
Msg 515, Level 16, State 2, Procedure TimeSheet_Insert_TimesheetEntry, Line 196
Cannot insert the value NULL into column 'Client_PK_ID', table 'ClientPayroll.dbo.tbl_TimesheetEntry'; column does not allow nulls. INSERT fails.
The statement has been terminated.
If the Client_PK_ID, the StepNumber_PK_ID and other info is correct, then why am I getting NULLS, a -6 return value and a msg telling me about a NULL Client_PK_ID?
I thought maybe the UNION would work, but I don't think that it is appropriate for this task.
Thanks,
Bill