【发布时间】:2017-09-06 11:31:15
【问题描述】:
我想做一个sql存储过程,作为水晶报表的数据源。我做了如下,它可以正常工作。
CREATE PROCEDURE [dbo].[sp_ScanPointPrint]
@branch varchar(50),
@tripID int,
@scanPoint varchar(50)
AS
BEGIN
SET NOCOUNT ON;
select sp.BranchCode, sp.ScanPoint, sp.TripId, sp.DoneBy,FORMAT(sp.DateTime,'dd MMMM, yyyy hh:mm tt'), sp.Driver, sp.CarNo, sp.ItemShouldBe, sp.ActualTaken, sp.MissedAny, sp.MissedCount, sp.TookExtra, sp.ExtraCount, spT.OrderNo,spt.ItemBarcode, oi.ItemName
from ScanPointLog as sp
left join TableScanPoint1 as spT on sp.BranchCode = spT.BranchCode and sp.TripId = spT.TripId
left join OrderItem as Oi on spt.OrderNo=oi.OrderNO and spt.ItemBarcode=oi.ItemBarcode
where sp.BranchCode=@branch and sp.ScanPoint=@scanPoint and spt.IsItem=1 and sp.TripId=@tripID
END
GO
我想要执行但我无法将TableScanPoint1 表名更改为另一个表名。 TableScanPoint1 到 TableScanePont8 共有 8 个表,结构相同,但数据不同。这样做的目的是让一个报表设计按照最终用户的需要使用它。最终用户将在运行时从 vb.net 应用程序中选择表、分支、tripid 和扫描点。
谁能帮我解决这个问题? 谢谢
【问题讨论】:
-
听起来像是一个损坏的数据模型。
1-8值的相关性是什么?通常,这实际上是 data,但它被错误地建模为 metadata(表名)。您现在在编写查询时遇到了困难,因为您需要查询此数据,但它不能作为数据使用。 -
即这应该是一个带有附加列的表,用于存储
1-8值以及当前分布在这 8 个表之间的所有数据。然后,您的查询将很容易创建。
标签: sql-server stored-procedures dynamic