問題描述
如何獲取t sql中的相對路徑?以.sql
文件位于D:\temp
文件夾為例,我想獲取D文件夾中hello.txt文件的路徑:\temp\App_Data
.如何使用相對路徑引用?
How to get the relative path in t sql? Take for example a .sql
file is located in the folder D:\temp
, I want to get path of the file hello.txt in the folder D:\temp\App_Data
. How to use the relative path reference?
假設我正在 SQL 服務器管理工??作室中執行 sql 文件.
Let's say I am executing the sql file inside the SQL server management studio.
推薦答案
服務器正在執行 t-sql.它不知道客戶端從哪里加載文件.您必須在腳本中嵌入路徑.
The server is executing the t-sql. It doesn't know where the client loaded the file from. You'll have to have the path embedded within the script.
DECLARE @RelDir varchar(1000)
SET @RelDir = 'D:\temp\'
...
也許您可以以編程方式將路徑放入 .sql 腳本文件中的 SET 命令中,或者您可以使用 sqlcmd 并將相關目錄作為變量傳入.
Perhaps you can programmatically place the path into the SET command within the .sql script file, or perhaps you can use sqlcmd and pass the relative directory in as a variable.
這篇關于t sql中的相對路徑?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!