在以下T-SQL代码中,如何将@Name
和P
括在引号中?
EXEC('xp_cmdshell ''echo IF EXISTS(SELECT * FROM sys.objects WHERE name = ' + @Name + ' AND type = P)>> C:\test.txt'', NO_OUTPUT')`
谢谢!
答案 0 :(得分:1)
试试这个:
declare @Name varchar(50)='test'
EXEC('xp_cmdshell ''echo IF EXISTS(SELECT * FROM sys.objects
WHERE name = ''''' + @Name + ''''' AND type = ''''P'''')>>
C:\test.txt'', NO_OUTPUT')