Tsql Insert into table变量使用select失败

Tsql Insert into table变量使用select失败,tsql,Tsql,我得到一个语法错误,说这个选择是错误的…不知道为什么 Insert into @MyTableVariable (select @new_identity, Name from Company where soemField = 'some text value') @new_identity只是在前面的insert语句之后设置为scope_identity()的int-var我不应该用那种语法来指定…指定要在值之前插入的字段。通常它是一个快捷方式,您只需选择不需要的字段(newIdentit

我得到一个语法错误,说这个选择是错误的…不知道为什么

Insert into @MyTableVariable (select @new_identity, Name from Company where soemField = 'some text value')

@new_identity只是在前面的insert语句之后设置为scope_identity()的int-var

我不应该用那种语法来指定…指定要在值之前插入的字段。通常它是一个快捷方式,您只需选择不需要的字段(newIdentityColName,nameName)您拼写的
soemField
是否正确?我想你不必这么做。如果有添加、删除或重新排列的列,这是一种很好的做法。@CoffeeAddict:请参阅感谢@marc_s的备份:)不,我可以将其放入其中,它会从select:select 1、soemField='some text value'中的公司名称返回有效数据。是,标识具有有效值。
Insert into @MyTableVariable (newIdentityColName, nameName)
   select @new_identity, Name from Company where someField = 'some text value'