我正在修改现有的SQL Server存储过程。我在表中添加了两个新列,并修改了存储过程以选择这两个列。尽管表中的列可用,但SQL Server始终出现此错误:
无效的列名“ INCL_GSTAMOUNT”
谁能告诉我这是怎么回事?
我正在修改现有的SQL Server存储过程。我在表中添加了两个新列,并修改了存储过程以选择这两个列。尽管表中的列可用,但SQL Server始终出现此错误:
无效的列名“ INCL_GSTAMOUNT”
谁能告诉我这是怎么回事?
Answers:
如果将字符串放在双引号而不是单引号中,也可能发生。
封装的SQL语句中也可能发生此错误,例如
宣告@tableName nvarchar(20)SET @tableName ='GROC'
宣告@updtStmt nvarchar(4000)
SET @updtStmt ='更新tbProductMaster_'+ @ tableName +'SET department_str ='+ @tableName exec sp_executesql @updtStmt
只是发现缺少引号来封装参数“ @tableName”,如下所示:
SET @updtStmt ='更新tbProductMaster_'+ @ tableName +'SET department_str ='''+ @tableName +''''
谢谢
我刚试过 如果执行该语句以生成本地表,则该工具将接受此列名存在。只需在编辑器窗口中标记表生成语句,然后单击执行即可。
如果要转到ALTER Table列并立即更新包含同一脚本中的新列的表。请确保GO
如下所示在alter table的代码行之后使用命令。
ALTER TABLE Location
ADD TransitionType SMALLINT NULL
GO
UPDATE Location SET TransitionType = 4
ALTER TABLE Location
ALTER COLUMN TransitionType SMALLINT NOT NULL
There can be many things:
First attempt, make a select of this field in its source table;
Check the instance of the sql script window, you may be in a different instance;
Check if your join is correct;
Verify query ambiguity, maybe you are making a wrong table reference
Of these checks, run the T-sql script again
[Image of the script SQL][1]
[1]: https://i.stack.imgur.com/r59ZY.png`enter code here
我注意到,在执行联接时,如果要联接MSSQL
的表不在要联接的表的旁边,则会抛出“无效的列名”。我尝试指定table1.row1
和table3.row3
,但是仍然出现错误;直到我对查询中的表重新排序后,它才消失。显然,语句中表的顺序很重要。
+-------------+ +-------------+ +-------------+
| table1 | | table2 | | table3 |
+-------------+ +-------------+ +-------------+
| row1 | col1 | | row2 | col2 | | row3 | col3 |
+------+------+ +------+------+ +------+------+
| ... | ... | | ... | ... | | ... | ... |
+------+------+ +------+------+ +------+------+
SELECT * FROM table1, table2 LEFT JOIN table3 ON row1 = row3; --throws an error
SELECT * FROM table2, table1 LEFT JOIN table3 ON row1 = row3; --works as expected