简单来说吧 比如你有一个表,名字叫 index 你有一个动态查询,参数是表名 declare @tbname varchar(256) set @tbname=’index’ —查这个表里的数据: print(‘select * from ‘+@tbname) exec(‘select * from ‘+@tbname) –这样print出来的数据是 select * from index 因为index是字键字,肯定出错,加上括号就可以了: select * from [index] 这便有了QUOTENAME,即: print(‘select * from ‘+QUOTENAME(@tbname)) –结果:select * from [index] exec(‘select * from ‘+QUOTENAME(@tbname))
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/164273.html原文链接:https://javaforall.cn