0

在以下 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')`

谢谢!

4

1 回答 1

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')
于 2012-08-20T06:58:58.770 回答