这是我下面的存储过程。我将@CultureCode
参数与视图名称连接起来,即 [_0002HR_EmployeeNames_ en-US _View]。部分 en-US 将通过名为 的参数传递@CultureCode
。有什么办法可以这样做,因为我要求不使用动态查询。谢谢你。
CREATE PROCEDURE [dbo].[_001HR_Report_Loans] (@Parameters VARCHAR(max))
AS
DECLARE @ReportOption VARCHAR(5) SET @ReportOption = [dbo].DB_Split(@Parameters, 1)
DECLARE @CultureCode VARCHAR(10) SET @CultureCode = [dbo].DB_Split(@Parameters, 2)
DECLARE @ShowItems VARCHAR(5) SET @ShowItems = [dbo].DB_Split(@Parameters, 3)
DECLARE @StartDate NVARCHAR(8) SET @StartDate = [dbo].DB_Split(@Parameters, 4)
DECLARE @EndDate NVARCHAR(8) SET @EndDate = [dbo].DB_Split(@Parameters, 5)
DECLARE @EmployeeCode NVARCHAR(30) SET @EmployeeCode = [dbo].DB_Split(@Parameters, 6)
DECLARE @BranchCode NVARCHAR(30) SET @BranchCode = [dbo].DB_Split(@Parameters, 7)
--IF @StartDate = ''
-- SET @StartDate = NULL
SELECT HR.*, EN.[Name] AS EmployeeName
FROM [0002HR_EmployeeLoans] HR
LEFT JOIN [_0002HR_EmployeeNames_ + '@CultureCode' +_View] EN ON HR.EmployeeCode = EN.EmployeeCode
LEFT JOIN [_0002HR_EmployeePackagesView] EP ON EP.EmployeeCode = HR.EmployeeCode
WHERE
(HR.EmployeeCode = @EmployeeCode OR @EmployeeCode IS NULL)
AND
(EP.BranchCode = @BranchCode OR @BranchCode IS NULL)
AND
(HR.Date BETWEEN @StartDate AND @EndDate OR @StartDate IS NULL AND @EndDate IS NULL)
AND
(HR.Date >= @StartDate OR @StartDate IS NULL)
AND
(HR.Date <= @EndDate OR @EndDate IS NULL)