简体   繁体   English

t-sql将数据追加到现有数据集

[英]t-sql append data to an existing dataset

I have a report writer that will allow me to query my db directly, however the query has to select from a SQL view. 我有一个报表编写器,可以直接查询我的数据库,但是查询必须从SQL视图中进行选择。 I have to develop a lot tracking solution but because of the logic involved, the only way I have been able to accomplish this so far is to hijack the SQL statement before it leaves the report writer and point it towards a function (instead of the view). 我必须开发很多跟踪解决方案,但是由于所涉及的逻辑,到目前为止,我能够完成此操作的唯一方法是在SQL语句离开报表编写器之前劫持该SQL语句,并将其指向一个函数(而不是视图)。 )。

I need to develop a more user friendly way to accomplish this. 我需要开发一种更加用户友好的方法来完成此任务。 My first though was to populate the view that the report writer sees with an item and lot number from one of my tables, call my function with the item and lot number and then somehow append the original view with usage and consumption transactions for that item/lot. 不过,我的第一个方法是使用我的一个表中的项目和批号填充报表编写者看到的视图,并使用项目和批号调用我的函数,然后以某种方式在原始视图中附加该项目的使用和消费交易/很多。 Because of how the report writer is designed, the original view that returns just the item/lot must be the same object as the view that is eventually populated with the transactions. 由于报表编写器的设计方式,仅返回项目/批次的原始视图必须与最终由事务填充的视图相同。

Is there a way to use an alter view statement as part of a query? 有没有一种方法可以将alter view语句用作查询的一部分? Is there a better way to accomplish this goal? 有没有更好的方法来实现这一目标? I am a bit lost here. 我在这里有点迷路。

Well not having the reputation to comment, and seeing that this is SQL Server could you do the following?: 好吧,没有声誉可以发表评论,并且看到这是SQL Server,您可以执行以下操作吗:

SELECT st.*
, dbo.ufn_usage_and_consumption(st.item_number, st.lot_number)
from some_table st

Basically, you are calling both the view and FOR EACH ROW of the view, calling the SQL Server Function. 基本上,您要同时调用视图和视图的FOR EACH ROW,同时调用SQL Server Function。

Please note that this is NOT OPTIMAL. 请注意,这不是最佳的。 You are essentially doing RBAR processing (Row by Agonizing Row) and calling the function for every row. 实质上,您正在执行RBAR处理(行通过使行变色),并为每一行调用该函数。

Really, I would see about creating a stored procedure, if your report writer supports that and pass parameters to call the query and pass results back. 的确,如果您的报表编写器支持该存储过程并传递参数以调用查询并将结果传递回去,那么我将创建存储过程。

I'm making the following assumption: 1) the data coming back from the function is a scalar (one value only), if it's not you can return it as a comma delimitted string 我做出以下假设:1)从函数返回的数据是标量(仅一个值),如果不是,则可以将其作为逗号分隔的字符串返回

Don't know if that helps or not but good luck with your query! 不知道这是否有帮助,但祝您查询顺利!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM