久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

SQL CMD:用括號和單引號傳遞變量

SQL CMD: pass variables with brackets and single quotes(SQL CMD:用括號和單引號傳遞變量)
本文介紹了SQL CMD:用括號和單引號傳遞變量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試創建一個腳本,該腳本為我提供了一些數據庫的大小.我已經創建了有效的原始查詢,但現在我想動態創建它.

I am trying to create a script that gives me the size of some databases. I have created the original query which works but now i want to make it dynamically.

我的腳本根據提交的變量創建一個臨時表.例如:

My script creates a temp table based on the variable that was submitted. for example:

        create table #temptbl (idx int IDENTITY(1,1), valuex varchar(256))
        INSERT INTO #temptbl (valuex) values ('PARTS'),('PARTS_Master'),('PARTS2_4'),('PARTS2_7'),('Projects')

腳本的其余部分然后遍歷此表中的行,并為我提供每個相應數據庫的大小.

The rest of the script then loops over the rows in this table and gives me the size of each corresponding database.

我正在考慮在 sqlcmd 中傳遞一個變量,如下所示:

I was looking into passing a variable in sqlcmd like so:

sqlcmd -v variables ="('PARTS'),('PARTS_Master'),('PARTS2_4'),('PARTS2_7'),('Projects')" -S MYSERVERNAME\sqlexpress -i DatabaseSize.sql -d Parts

然后在我的 sql 腳本中我像這樣改變它:

and then in my sql script I changed it like this:

        create table #tables (idx int IDENTITY(1,1), valuex varchar(256))
        INSERT INTO #tables (valuex) values '$(variables)'

然而這給了我一個錯誤:

This however gives me an error:

Msg 102, Level 15, State 1, Server ServerName\SQLEXPRESS, Line 16
Incorrect syntax near '('.

感謝您的幫助.

推薦答案

考慮以下代碼:

create table #tables (idx int IDENTITY(1,1), valuex varchar(256))
INSERT INTO #tables (valuex) values '$(variables)'

變量替換后變成:

create table #tables (idx int IDENTITY(1,1), valuex varchar(256))
INSERT INTO #tables (valuex) values '('PARTS'),('PARTS_Master'),('PARTS2_4'),('PARTS2_7'),('Projects')'

請注意,行構造函數列表用單引號括起來,導致 T-SQL 語法無效.所以解決方案是簡單地刪除 SQLCMD 變量周圍的引號:

Note the list of row constructors is enclosed in single quotes, resulting in invalid T-SQL syntax. So the solution is to simply remove the quotes around the SQLCMD variable:

CREATE TABLE #tables (idx int IDENTITY(1,1), valuex varchar(256))
INSERT INTO #tables (valuex) VALUES $(variables);

這篇關于SQL CMD:用括號和單引號傳遞變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
Converting the name of a day to its integer representation(將一天的名稱轉換為其整數表示)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉換為 mm/dd/yyyy?)
主站蜘蛛池模板: 久久中文一区二区 | 欧美黄色网 | 夜夜夜久久| 毛片免费视频 | 中文字幕乱码亚洲精品一区 | 国产91色在线 | 亚洲 | 日韩欧美在线一区二区 | 黄色片av | 亚洲国产精品一区二区久久 | 国产一区二区日韩 | 成人精品国产 | 中文字幕一区二区三区乱码在线 | 精品一区二区三区在线播放 | 三级成人在线观看 | 成人亚洲网 | 亚洲午夜精品一区二区三区他趣 | 久久av网| 亚洲精品68久久久一区 | 日韩二| 影音先锋男| 天天射美女 | 成人性视频免费网站 | 视频一区二区三区中文字幕 | 日本精品一区二区三区在线观看视频 | 国产高清视频一区 | 蜜桃黄网 | 亚洲视频在线播放 | 欧美影院久久 | 久久视频免费观看 | caoporn国产精品免费公开 | 自拍偷拍亚洲视频 | 久久久久久国产 | 中国大陆高清aⅴ毛片 | 91九色porny首页最多播放 | 丁香综合| 成人午夜毛片 | 国产精品网址 | 日韩一区二区三区在线观看视频 | 国产精品久久久久久久久污网站 | 一级毛片免费看 | 伊人欧美视频 |