在执行SQLCommand(选择)查询后命名DataSet.table [英] Naming DataSet.table after performing SQLCommand (Select) Query
问题描述
在存储过程MS SQL中,我的查询是:
In stored procedure MS SQL My query is:
SELECT *
FROM ContentReportRequests a,UserPreferences d
WHERE a.UserID = d.UserID and a.ID =@ID
我想给结果表起一个名字. 我该怎么办?
I want to give the result table some name. How can I do this ?
我想将其拉到ADO.Net DataSet.tables ["NAME"]
I want to pull it to ADO.Net DataSet.tables["NAME"]
推荐答案
我能想象出您可能要说明的几件事.
I can imagine a few things you might be meaning.
如果您要保留此结果集,以供以后多个查询使用,则可能需要查找SELECT INTO:
If you want to persist this result set, for consumption in multiple later queries, you might be looking for SELECT INTO:
SELECT * into NewTableName
FROM ContentReportRequests a,UserPreferences d
WHERE a.UserID = d.UserID and a.ID =@ID
NewTableName
是新名称,并且将创建一个新的(永久)表.如果要在完成后删除该表,请在名称前加上#
使其成为临时表.
Where NewTableName
is a new name, and a new (permanent) table will be created. If you want that table to go away when you're finished, prefix the name with a #
, to make it a temp table.
或者,您可能只想将其吸收到一个较大的查询中,在这种情况下,您将要使其成为子选择:
Alternatively, you might just be wanting to absorb it into a single larger query, in which case you'd be looking at making it a subselect:
SELECT *
FROM (SELECT *
FROM ContentReportRequests a,UserPreferences d
WHERE a.UserID = d.UserID and a.ID =@ID
) NewTableName
WHERE NewTableName.ColumnValue = 'abc'
或CTE:
WITH NewTableName AS (
SELECT *
FROM ContentReportRequests a,UserPreferences d
WHERE a.UserID = d.UserID and a.ID =@ID
)
SELECT * from NewTableName
最后,您可能正在谈论将结果集提取到例如ADO.Net DataTable,并且您想要自动设置名称.我不确定这是否可行.
Finally, you might be talking about pulling the result set into e.g. an ADO.Net DataTable, and you want the name to be set automatically. I'm not sure that that is feasible.
这篇关于在执行SQLCommand(选择)查询后命名DataSet.table的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!