Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tsql 如何在T-SQL和SQLCMD脚本中连接常量字符串?_Tsql_Variables_Concatenation_Sqlcmd - Fatal编程技术网

Tsql 如何在T-SQL和SQLCMD脚本中连接常量字符串?

Tsql 如何在T-SQL和SQLCMD脚本中连接常量字符串?,tsql,variables,concatenation,sqlcmd,Tsql,Variables,Concatenation,Sqlcmd,我还在学习T-SQL和SQLCMD脚本的基础知识 是否可以将字符串(作为父文件夹路径)与其他字符串(作为子文件夹路径)连接起来 我已经看到了一些以前的线程,但还没有找到解决方案 谢谢你的见解 -- Global variables DECALRE @PARENT_PATH NVARCHAR(256); SET @PARENT_PATH = 'parent_path'; -- OK, works but I've seen some string ending with '%'.. -- Som

我还在学习T-SQL和SQLCMD脚本的基础知识

是否可以将字符串(作为父文件夹路径)与其他字符串(作为子文件夹路径)连接起来

我已经看到了一些以前的线程,但还没有找到解决方案

谢谢你的见解

-- Global variables
DECALRE @PARENT_PATH NVARCHAR(256);
SET @PARENT_PATH = 'parent_path'; -- OK, works but I've seen some string ending with '%'..

-- Some steps to check if the database already exists and deals with it
-- ..

-- Database creation
CREATE DATABASE [MyDatabase]
ON
    (NAME = "MyDatabase",
    FILENAME = @PARENT_PATH + "MyDatabase.mdf") -- How to do it? I know the CONCAT() function, but doesn't seem to work. Should I define and set another intermediate variable, instead of concatenating it directly?
LOG ON
    (Name = "MyDatabase_log",
    FILENAME = @PARENT_PATH + "MyDatabase_log.ldf")
GO

-- Table creation
-- ..

-- Executes stored procedures scripts (SQLCMD) where each stored procedure is written in a separate file
:setvar STORED_PROCEUDRE_PATH @PARENT_PATH + "Stored Procedures\" -- How to do it?

:r $(STORED_PROCEUDRE_PATH)spStoreProcedureName.sql

-- By the way, still need to get used to the following SQLCMD loop syntax 
-- FOR %%Script IN ($(STRORE_PROCEDURE_PATH)*.sql) DO sqlcmd /S servername /d MyDatabase -E -i" %%Script"
-- PAUSE