我有以下TSQL声明:
SELECT ProductId, OwnerId FROM Product
Run Code Online (Sandbox Code Playgroud)
如何将ProductId和OwnerId存储在TSQL变量中,然后将其返回给调用应用程序?
一般情况下,如果没有像分隔列表那样的跳跃跳跃,你不能在变量中存储多个值.在您的示例中,假设Product表有一行,您可以执行以下操作:
Declare @ProductId <datatype>
Declare @OwnerId <datatype>
Select @ProductId = ProductId
, @OwnerId = OwnerId
From Product
Run Code Online (Sandbox Code Playgroud)
如果Product表有多行,这将无法工作,接下来需要做什么在很大程度上取决于您实际要完成的任务.