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

SQL CMD:用括號(hào)和單引號(hào)傳遞變量

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

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我正在嘗試創(chuàng)建一個(gè)腳本,該腳本為我提供了一些數(shù)據(jù)庫(kù)的大小.我已經(jīng)創(chuàng)建了有效的原始查詢,但現(xiàn)在我想動(dòng)態(tài)創(chuàng)建它.

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.

我的腳本根據(jù)提交的變量創(chuàng)建一個(gè)臨時(shí)表.例如:

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')

腳本的其余部分然后遍歷此表中的行,并為我提供每個(gè)相應(yīng)數(shù)據(jù)庫(kù)的大小.

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

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

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)'

然而這給了我一個(gè)錯(cuò)誤:

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')'

請(qǐng)注意,行構(gòu)造函數(shù)列表用單引號(hào)括起來(lái),導(dǎo)致 T-SQL 語(yǔ)法無(wú)效.所以解決方案是簡(jiǎn)單地刪除 SQLCMD 變量周圍的引號(hào):

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);

這篇關(guān)于SQL CMD:用括號(hào)和單引號(hào)傳遞變量的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應(yīng)該使用什么 SQL Server 數(shù)據(jù)類型來(lái)存儲(chǔ)字節(jié) [])
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() 是否應(yīng)該返回“1?什么時(shí)候不能投射為日期?)
Converting the name of a day to its integer representation(將一天的名稱轉(zhuǎn)換為其整數(shù)表示)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉(zhuǎn)換為 mm/dd/yyyy?)
主站蜘蛛池模板: 免费激情网站 | 青青久久av北条麻妃海外网 | 亚洲综合色网站 | 91国产精品| 91原创视频 | 综合久久一区 | 久久久精品影院 | 日韩欧美一区二区三区四区 | 成人高潮片免费视频欧美 | 久久久新视频 | 国产成人精品一区二区三 | 欧美一级欧美三级在线观看 | 国产欧美一区二区精品忘忧草 | 亚洲精品在线播放 | 超碰av免费 | 精品一区二区三区视频在线观看 | 国产精品伦一区二区三级视频 | 国产一区二区在线免费观看 | 草久久| 成人做爰www免费看视频网站 | 91婷婷韩国欧美一区二区 | 欧美亚洲视频在线观看 | 亚洲欧美视频 | 午夜成人免费视频 | 午夜专区 | 成人做爰www免费看 午夜精品久久久久久久久久久久 | 久久专区 | 色婷婷综合在线观看 | 精品国产第一区二区三区 | 亚洲视频在线免费观看 | 国产高清av免费观看 | 精品国产乱码久久久久久丨区2区 | 爱综合| 精品欧美乱码久久久久久 | 国产精品精品久久久 | 在线播放91 | 91在线精品视频 | 精品国产一区二区三区成人影院 | 亚洲第一免费播放区 | 中文字幕一区二区在线观看 | 欧美一级大片 |