尽管检查了它,但列名无效 [英] Invalid column name despite checking for it
本文介绍了尽管检查了它,但列名无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我试图检查字段(isParent)是否存在,如果不存在,则打印一条消息并停止。如果存在,则继续基于两个选项中的一个。但是,当我知道该字段不存在时,它会在isParent的第一个实例上抛出无效的字段错误。它为什么这样做?
谢谢
Hello,
Im trying to check if a field (isParent) exists and if it doesn't, print a message and stop. If it exists, continue based one one of two choices. However, when I know the field doesnt exist, it throws an invalid field error on the first instance of isParent is Null. Why is it doing this?
Thanks
declare @RUNTYPE varchar(20);
--set @RUNTYPE = 'Incremental Run'
set @RUNTYPE = 'Full Run';
--select COL_LENGTH('eddsdbo.document','isParent')
IF COL_LENGTH('eddsdbo.document','isParent') is NULL
PRINT 'isParent field is missing. Please create it and retry.'
ELSE
BEGIN
IF @RunType = 'Incremental Run' --AND COL_LENGTH('eddsdbo.document','isParent') is not null
BEGIN
--populate yes for parent docs and run first
update EDDSDBO.DOCUMENT
set isParent = 1
where ((BEGATTACH is NULL) or (BEGDOC = BEGATTACH))
and isParent is NULL
--remaining docs with isParent = NULL should be set to No at this point
update EDDSDBO.DOCUMENT
set isParent = 0
where isParent is NULL
PRINT 'Incremental run successful!'
END
ELSE --IF @RunType = 'Full Run'
BEGIN
update EDDSDBO.DOCUMENT set isParent = NULL
--populate yes for parent docs and run first
update EDDSDBO.DOCUMENT
set isParent = 1
where ((BEGATTACH is NULL) or (BEGDOC = BEGATTACH))
and isParent is NULL
--remaining docs with isParent = NULL should be set to No at this point
update EDDSDBO.DOCUMENT
set isParent = 0
where isParent is NULL
PRINT 'Full run successful!'
END
END
推荐答案
最后一行出现的错误:
Errors on the last line where it says:
--remaining docs with isParent = NULL should be set to No at this point
update EDDSDBO.DOCUMENT
set isParent = 0
where isParent is NULL
错误是:
Error is:
Msg 207, Level 16, State 1, Line 19
Invalid column name 'isParent'.
感谢您的帮助。
Thanks for your help.
显然最终为我工作的解决方案 - 将部分代码作为动态SQL传递。
So apparently the solution that ended up working for me - passing parts of the code as dynamic SQL.
这篇关于尽管检查了它,但列名无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文