久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 UDF 參數提供 SELECT 語句的 FROM 子句

How do I supply the FROM clause of a SELECT statement from a UDF parameter(如何從 UDF 參數提供 SELECT 語句的 FROM 子句)
本文介紹了如何從 UDF 參數提供 SELECT 語句的 FROM 子句的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在我正在移植到 Web 的應用程序中,我們目前在運行時根據指定的模板"字符串在運行時動態訪問不同的表.既然我們要遷移到 SQL 服務器,我想將執行此操作的負擔移回數據庫,這樣我就不必弄亂動態 GridView.我想寫一個表值 UDF,其中一個參數用于表名,一個用于查詢 WHERE 子句.

In the application I'm working on porting to the web, we currently dynamically access different tables at runtime from run to run, based on a "template" string that is specified. I would like to move the burden of doing that back to the database now that we are moving to SQL server, so I don't have to mess with a dynamic GridView. I thought of writing a Table-valued UDF with a parameter for the table name and one for the query WHERE clause.

我為我的 UDF 輸入了以下內容,但顯然它不起作用.有沒有辦法獲取某種類型的 varchar 或字符串并獲得可以在 FROM 子句中工作的表引用?

I entered the following for my UDF but obviously it doesn't work. Is there any way to take a varchar or string of some kind and get a table reference that can work in the FROM clause?

CREATE FUNCTION TemplateSelector 
(   
@template varchar(40),
@code varchar(80)
)
RETURNS TABLE 
AS
RETURN 
(
SELECT * FROM @template WHERE ProductionCode = @code
)

或者其他一些獲得與此概念類似的結果集的方法.基本上表中的所有記錄都由 varchar @template 和 @code 的匹配 ProductionCode 指示.

Or some other way of getting a result set similar in concept to this. Basically all records in the table indicated by the varchar @template with the matching ProductionCode of the @code.

我收到錯誤必須聲明表變量@template"",因此 SQL Server 可能是我試圖從表變量中選擇的內容.

I get the error "Must declare the table variable "@template"", so SQL server probably things I'm trying to select from a table variable.

關于是的,我不需要在函數中執行此操作,我可以運行存儲過程,我以前從未編寫過它們.

On Yeah I don't need to do it in a function, I can run Stored Procs, I've just not written any of them before.

推薦答案

CREATE PROCEDURE TemplateSelector 
(   
    @template varchar(40),
    @code varchar(80)
)

AS
EXEC('SELECT * FROM ' + @template + ' WHERE ProductionCode = ' + @code)

這有效,雖然它不是 UDF.

This works, though it's not a UDF.

這篇關于如何從 UDF 參數提供 SELECT 語句的 FROM 子句的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 一区二区三区成人 | 一区二区三区在线观看免费视频 | 国产精品一区久久久 | 天天拍天天色 | 午夜一区二区三区视频 | 狠狠色狠狠色综合系列 | 亚洲精品九九 | 久久久久久av | 国产精品一区二区久久 | 国产精品人人做人人爽 | 国产精品精品3d动漫 | 一区二区三区高清 | 男人天堂视频在线观看 | 久久久网| 日韩一级在线 | 国产日韩欧美中文字幕 | 日韩在线中文字幕 | 日韩小视频| 成人特级毛片 | 欧美色综合一区二区三区 | 国产精品免费一区二区三区四区 | 91极品视频 | 高清免费av | 综合久| 蜜臀网站 | 国产日韩欧美中文字幕 | 中文字幕精品视频在线观看 | 精品一区视频 | 久久久国产一区二区三区四区小说 | 国产毛片久久久 | 国产日韩欧美 | 亚洲精品在线免费看 | 精品久久久久久国产 | 99精品99久久久久久宅男 | 午夜国产精品视频 | 欧美一区二区在线 | 亚洲播放 | 高清免费av | 国产一区二区三区色淫影院 | 日韩在线免费电影 | 久久91精品国产 |