我如何将值放在变量内的表上?

我需要放入表中已经列出的文件名,我需要将文件名放入地址以访问文件  我已经尝试过了

DECLARE @filename AS varchar(255)
DECLARE @filepath AS varchar (255)
--SELECT MAX(id) FROM ##TempFileName

SET @filename = 'SELECT tfn.subdirectory FROM ##TempFileName tfn WHERE id = ''1'''
EXEC (@filename)
--PRINT @filename 

set @filepath = 'D:\romli\LockAmount_out\' + @filename  + '.txt'
EXEC (@filepath)
PRINT @filepath

我希望@filepath会包含以下内容:D:\ romli \ LockAmount_out \ 123456.txt,我如何在表中存储文件名以存储在变量中?

评论
o梦倾城
o梦倾城

why do you need to use Dynamic SQL to get @filename ?

您可以直接直接查询

SELECT @filename = tfn.subdirectory 
FROM   ##TempFileName tfn 
WHERE  tfn.id = '1'
点赞
评论