sqlcmd

Creating SQL Server database from vb.net, without SQL Server

时间秒杀一切 提交于 2019-12-12 19:16:23
问题 I'm programming an installer for an application in VB.net. My application needs a SQL Server database to work, but I want that my app runs in machines without SQL Server instances installed. Exists sqlcmd standalone or something? (I would like to include it in my installation pack) Is possible create a database via sqlcmd this way? Thank you 回答1: If you want to use the full power of the SQL Server Database you need to install an instance of SQL Server. If the problem is the cost for the final

sqlcmd on Azure SQL Data Warehouse - SqlState 24000, Invalid cursor state after INSERT statement

三世轮回 提交于 2019-12-12 19:03:22
问题 I am working on a script to reload a table using SQLCMD on Linux connecting to an Azure SQL Data Warehouse database. After the INSERT statement completes, the next statement fails (but does not end the sqlcmd execution) with the "warning" insert into schema.table_temp ( ...list of columns ) select ...list of columns from schema.table ; GO (COMMENT--> in script, but not echoed in log.) (0 rows affected) IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES t WHERE TABLE_TYPE = 'BASE

Executing CREATE VIEW & ALTER VIEW from SQLCMD

放肆的年华 提交于 2019-12-12 12:27:34
问题 I'm trying to execute a sql file with the following contents using sql cmd. sqlcmd -S localhost\dbInstance -i Sample.sql -v filepath="C:\Sql\" Sample.sql contents: USE Sample_db GO BEGIN BEGIN TRANSACTION; BEGIN TRY CREATE VIEW [dbo].[Test_View] AS SELECT * from Sample_table; ALTER VIEW [dbo].[Sample_View] AS SELECT * FROM table_9; ALTER TABLE [Sample_Table_2] ADD Col_4 VARCHAR(20); END TRY BEGIN CATCH SELECT ERROR_NUMBER() AS ErrorNumber , ERROR_SEVERITY() AS ErrorSeverity , ERROR_STATE() AS

sqlcmd with output file and screen output

橙三吉。 提交于 2019-12-12 11:13:56
问题 I do some command line batch (.bat) with sqlcmd as this way: sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE and i need an output file (it's works currently) and also the output trought the screen to do something like: @echo off echo The result of the query was: sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE pause CHOICE /C:YN /M "Is the result accord?" IF ERRORLEVEL 2 GOTO ENDWITHERROR IF ERRORLEVEL 1 GOTO STEP2 Note : Yes, the script works

How to use TAB as column separator in SQLCMD

亡梦爱人 提交于 2019-12-12 07:14:41
问题 SQLCMD supports the -s parameter to specify the column separator, but I couldn't figure how how to represent the tab (CHAR(9)) character. I have tried the following but both don't work: sqlcmd -S ServerName -E -Q"select * from mytable" -s"\t" -o results.txt sqlcmd -S ServerName -E -Q"select * from mytable" -s'\t' -o results.txt Any ideas how to do this in SQLCMD? 回答1: In a batch file, putting a tab between the double quotes works. sqlcmd -S ServerName -E -Q"select * from mytable" -s" " -o

Cmd.exe output in Chinese

和自甴很熟 提交于 2019-12-12 02:27:58
问题 My batch file started to write output to log file in Chinese. Code: echo ============= >> D:\path\file.log echo. >> D:\path\file.log echo. >> D:\path\file.log echo Import new data to table %date% D:\path\file.log sqlcmd -S (local)\sqlexpress -E -d DB_Name -Q "exit(exec[dbo].[StoredProcedure])" >> D:\path\file.log It worked fine for many months and all of a sudden it started to write the whole output in weird format like here: 㴽㴽㴽㴽㴽㴽‽਍ഠ ਍浉潰瑲渠睥搠瑡⁡潴匠䍒剟䵅䑅彙䅒⁗慴汢⁥㤰〯⼲〲㘱ഠ

create Scheduler task to invoke SQLCMD

末鹿安然 提交于 2019-12-11 20:13:37
问题 I have a Requirement where i have to run a SQL Script in SQL server on a weekly basis .Result of this script has to be mailed.I want to automate this process.I don't want to go with SSIS Jobs. I have searched i have found few options like Creating a Windows Scheduler task to invoke a SQLCMD.Can Someone Assist on how to create Scheduler task to invoke SQLCMD 回答1: Your best bet would be to create a Console Application which executes the SQL Command and performs the email. You can then use setup

Scripting variable to environment variable and vice versa

删除回忆录丶 提交于 2019-12-11 19:48:37
问题 Can we pass values of scripting variables to environment variables when we are witing codes in sqlcmd scripts or batch scripts and vice versa ? 回答1: Using batch variables in sqlcmd a) Directly placing them in the command line. The cmd parser will expand the variables to the value as it is written in the line set "lastName=Smith" sqlcmd -Q "SELECT * From myTable Where LastName='%lastName%'" b) Using declared variables in the sql query, and using the previous method to declare them in the

How do i remove the header Dashed underline from a file generated by SQLCMD in a batch file?

强颜欢笑 提交于 2019-12-11 16:39:19
问题 How do i remove the header underline from a file generated by SQLCMD in a batch file? I am trying to automate a process that puts a file in a directory to be processed by another app and it chokes on the dashed line under the header Example: 1. Header1 Header2 header3 header4 2. ------ ------ ------ ------ 3. Data1 Data2 Data3 Data4 4. Data1 Data2 Data3 Data4 5. Data1 Data2 Data3 Data4 6. Data1 Data2 Data3 Data4 I need to remove line 2. so the other app does not choke on it. The app needs the

SQL Server's sqlcmd is truncating my columns returned, and increasing the size causes no result

為{幸葍}努か 提交于 2019-12-11 16:21:34
问题 I'm using SqlCMD in SQL Server to query my database from my linux machine using the following bash code: RESULT=`/opt/mssql-tools/bin/sqlcmd -S thedb.server.database.windows.net -d db_123 -U user_123 -P pass_123 -y 50 -Y 50 -I -Q "$SQL_QUERY" -s"|"` This returns the each column up to 50 characters per column. However, some of my columns go up to 1000 chars in length, and when I include the "-y" and the "-Y" setting, it works up until about 80, then no result. I've reviewed Microsoft's docs