开发者

How can I set multiple T-SQL variables in a single SELECT query?

I have 3 variables: @testid, @sampleid and @clientid.

How can I set @sampleid and @clientid by executing this query once?

SELECT
  [sample].sampleid,
  [client].开发者_如何转开发clientid
FROM
  dbo.[test]
  LEFT OUTER JOIN dbo.[sampleslice] ON dbo.[test].samplesliceid = dbo.[sampleslice].samplesliceid
  LEFT OUTER JOIN dbo.[sample] ON dbo.[sampleslice].sampleid = dbo.[sample].sampleid
  LEFT OUTER JOIN dbo.[client] ON dbo.[sample].clientid = dbo.[client].clientid
WHERE
  testid = @testid


DECLARE @sampleid YOUR_VAR_TYPE;
DECLARE @clientid YOUR_VAR_TYPE;

SELECT
   @sampleid = [sample].sampleid, 
   @clientid = [client].clientid
FROM dbo.[test]


-- The variables are now initialized. You can now use them below.above
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜