sql情况下的情况,如果条件通过
我不知道如何添加最后一个条件。 这是动态代码 +光标的一部分。光标由表列列表组成。我正在比较两个表格中相同结构,将它们连接到PK的表格中的值,并在值不匹配的时候检查一列。 我在最后一个条件下需要的是:
- 是'untcode'
- 那么我想排除tmc.untcode无效的行
- ,
DECLARE @columnName CHAR(10) = 'untcode';
SELECT MC.@columnName, TMC.@columnName
FROM dbo.firstable AS TMC
INNER JOIN dbo.secondtable AS MC
ON MC.ID = TMC.ID
AND MC.Code = TMC.Code
WHERE MC.ID = 123
AND TMC.@columnName<> MC.@columnName
--How do I add this??
AND TMC.@columnName CASE
WHEN @columnName='untCode' THEN not null
ELSE --What???
END ;
如果@columnname
I cannot figure out how to add the last condition.
This is part of dynamic code + cursor. Cursor consists of a list of table columns. I am comparing values in two tables that are identical in their structure, joining them on PK, and checking one column at a time where the values are not matching.
What I need in my last condition is:
- if @columnName is 'untCode'
- then I want to exclude those rows where TMC.untCode is null
- otherwise this condition does not apply
DECLARE @columnName CHAR(10) = 'untcode';
SELECT MC.@columnName, TMC.@columnName
FROM dbo.firstable AS TMC
INNER JOIN dbo.secondtable AS MC
ON MC.ID = TMC.ID
AND MC.Code = TMC.Code
WHERE MC.ID = 123
AND TMC.@columnName<> MC.@columnName
--How do I add this??
AND TMC.@columnName CASE
WHEN @columnName='untCode' THEN not null
ELSE --What???
END ;
Appreciate the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所说的那样:
或者略有更改:
但是您应该更正
和tmc。@columnName&lt;&gt; @larnu所说的mc。 @columnName
;您的意思是和tmc.columnname = mc.columnname`吗?As you said it:
or with a slight change:
But you should correct
AND TMC.@columnName<> MC.@columnName
as @Larnu said; did you mean AND TMC.columnName=MC.columnName`?