Tsql 如何在T-SQL和SQLCMD脚本中连接常量字符串?
我还在学习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
-- 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