【发布时间】:2023-03-18 22:28:02
【问题描述】:
我必须在 asp.net 中创建一个 RDLC 报告。为此,我正在使用不同的标量函数编写存储过程。 我有一个 GUI,我必须从中选择一个标准并根据该标准收集数据。图形用户界面在这里: 我已经实现了所有案例,例如“所有员工”、“所有服务”等,但是当我必须从列表框中选择特定记录并据此带来数据时,问题就来了。例如,我从列表中选择特定的员工记录,我的报告应显示仅具有该选定记录的记录。 我该如何处理?我的意思是当我从列表框中选择一些记录时,如何将这些记录带到我的存储过程的 where 子句中以及如何在那里使用它?
我正在使用 SQL SERVER 2008。 我的存储过程是:
USE [PC_Rewrite]
去 设置 ANSI_NULLS ON 走 设置 QUOTED_IDENTIFIER ON 走 更改程序 [dbo].[spGetClients] ( @orderBy varchar(50) )
作为 开始 -- 添加了 SET NOCOUNT ON 以防止额外的结果集 -- 干扰 SELECT 语句。 设置无计数;
-- Insert statements for procedure here
IF(@orderBy = 'Consumer Name')
BEGIN
SELECT c.Id, c.LastName, c.FirstName, c.MiddleInit,
c.DateOfBirth, dbo.GetAge(c.DateOfBirth, GETDATE()) AS Age, c.Sex, cs.Status, ca.Address, co.Phone,
dbo.GetEthnicity(c.Id) AS Ethnicity, dbo.GetDevelopmentalDisabilities(c.Id) AS Disabilities,
dbo.GetClientStaffContacts(c.Id) AS Staff, dbo.GetClientContacts(c.Id) AS Contact,
dbo.GetClientInsuranceProviders(c.Id) AS InsuranceProvider FROM Client c
LEFT OUTER JOIN ClientStatus cs ON cs.Id = c.StatusId
LEFT OUTER JOIN(
SELECT ca.ParentEntityId, ca.Address
FROM ContactAddress ca
INNER JOIN EntityName en ON en.Id = ca.EntityNameId AND en.Name = 'Client'
INNER JOIN GeneralLookup gl ON ca.glAddressTypeId = gl.Id AND gl.LookupItem = 'Primary'
) ca ON c.Id = ca.ParentEntityId
LEFT OUTER JOIN(
SELECT co.ParentEntityId, co.ContactData Phone
FROM ContactOther co
INNER JOIN EntityName en ON en.Id = co.EntityNameId AND en.Name = 'Client'
INNER JOIN GeneralLookup gl ON co.glContactTypeId = gl.Id AND gl.LookupItem = 'Home'
) co ON c.Id = co.ParentEntityId
ORDER BY c.LastName, c.FirstName, c.MiddleInit
END
ELSE IF(@orderBy = 'Consumer Address')
BEGIN
SELECT c.Id, c.LastName, c.FirstName, c.MiddleInit,
c.DateOfBirth, dbo.GetAge(c.DateOfBirth, GETDATE()) AS Age, c.Sex, cs.Status, ca.Address, co.Phone,
dbo.GetEthnicity(c.Id) AS Ethnicity, dbo.GetDevelopmentalDisabilities(c.Id) AS Disabilities,
dbo.GetClientStaffContacts(c.Id) AS Staff, dbo.GetClientContacts(c.Id) AS Contact,
dbo.GetClientInsuranceProviders(c.Id) AS InsuranceProvider FROM Client c
LEFT OUTER JOIN ClientStatus cs ON cs.Id = c.StatusId
LEFT OUTER JOIN(
SELECT ca.ParentEntityId, ca.Address
FROM ContactAddress ca
INNER JOIN EntityName en ON en.Id = ca.EntityNameId AND en.Name = 'Client'
INNER JOIN GeneralLookup gl ON ca.glAddressTypeId = gl.Id AND gl.LookupItem = 'Primary'
) ca on c.Id = ca.ParentEntityId
LEFT OUTER JOIN(
SELECT co.ParentEntityId, co.ContactData Phone
FROM ContactOther co
INNER JOIN EntityName en ON en.Id = co.EntityNameId AND en.Name = 'Client'
INNER JOIN GeneralLookup gl ON co.glContactTypeId = gl.Id AND gl.LookupItem = 'Home'
) co ON c.Id = co.ParentEntityId
ORDER BY ca.Address
END
结束
任何帮助将不胜感激。
【问题讨论】:
标签: asp.net sql sql-server criteria user-defined-functions