Relative path in t sql?(t sql中的相对路径?)
问题描述
如何获取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中的相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:t sql中的相对路径?
基础教程推荐
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
