开发者

Getting value from one table and querying another with that value

I have the following tables:

TableA
---------------
ParamA ¦ ParamB
---------------
  695  ¦  Test

TableB
---------------
ParamA ¦ ParamC
---------------
  695  ¦ Test2

So I am trying to create a stored procedure that will SELECT ParamA FROM TableA WHERE开发者_开发知识库 ParamB = @ParamB and UPDATE ParamC = 'NULL' in TableB WHERE ParamA = ParamA FROM TableA

What I have so far is this:

UPDATE ClassDetails
SET ValidTo = 'NULL'
WHERE Class = Classes.ClassId AND Classes.ClassName = @ClassName;

I know the above is wrong but that is my logic regarding it...

Any ideas?


It's kind of hard to follow your reasoning but if I did understood you correct, following update would suit your needs.

UPDATE b
SET    ParamC = NULL
FROM   TableB b
       INNER JOIN TableA a ON a.ParamA = b.ParamA
WHERE  a.ParamB = @ParamB

Syntax for UPDATE FROM

FROM < table_source >

Specifies that a table is used to provide the criteria for the update operation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜