8

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

1 Answer 1

24
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
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for replying so quickly. I have one more coming in about a minute. :-) Should be the last for today.
@Mr. MacGyver: you can probably combine this with your INSERT in the other question by JOINs on this table and notes. The WHERE in the other question becomes the JOIn onto "test"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.