sqlcmd

Remove column header from SQL Server query result

余生长醉 提交于 2019-12-06 02:36:31
问题 I want to remove column header from SQL Server query output. I did the search but not found any solution. I have a query eg. select cc.DepartmentID , cc.Name from HumanResources.Department cc When I run this query I am getting output like this. ID Name 12 Document Control 1 Engineering 16 Executive 14 Facilities and Maintenance 10 Finance 9 Human Resources I want to remove ID and Name (Column Header) from the output in SQL Server. I will run this query by script to generate csv file. Edit:

How do I run a script using a BAT file?

隐身守侯 提交于 2019-12-05 20:31:14
问题 I would like to have a BAT file open a sql server script. Currently I have this code in the sql file: declare @path varchar(255), @mydb varchar(50) SELECT @mydb = 'timeclockplus' select @path = 'C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Backup\' + @mydb + '-' + convert(varchar(8),getdate(),112) + '.bak' BACKUP DATABASE @mydb TO DISK = @path How do I open this SQL file from a BAT file? I am currently trying to run it like this: C:\Program Files\Microsoft SQL Server\80\Tools\Binn\osql

How to format SQLCMD output

筅森魡賤 提交于 2019-12-05 17:22:07
问题 I am using below command line to run a SQL query using SQLCMD sqlcmd -S Server -Q "select top 100 * From people" -d people -t 10 The table has 20 columns and when i look at output command line window wraps the text and makes it difficult to read. I want my results to be displayed the same way it displays in SQL Server Management Studio (properly formatted). I am not looking for any grids, but i need all my columns to be displayed in row 1 and the results properly beneath. Thanks in advance.

How can I run sqlcmd.exe from an ASP page?

醉酒当歌 提交于 2019-12-05 13:18:42
As part of our database revision control (and auto-installation) procedures we need to be able run sqlcmd.exe on various .sql files from within an ASP page. The code I'm using to do this is: Dim cmd : cmd = "sqlcmd -S " & DATABASE_SERVER & " -U " & DATABASE_UID & " -P " & DATABASE_PWD & " -d " & DATABASE_NAME & " -i """ & scriptPath & """ -b" Dim wshShell : Set wshShell = Server.CreateObject("WScript.Shell") Dim return : return = wshShell.Run(cmd, 0, True) I have the code working on my development machine (running XP) but now that I've deployed it to our Windows 2003 server it's having

Can you make SQLCMD immediately run each statement in a script without the use of “GO”?

房东的猫 提交于 2019-12-05 10:43:51
When running a script in SQLCMD, is there a setting, parameter or any other way of making it effectively run a GO command at the end of each SQL statement? This would prevent the need to insert periodic GO commands into very large scripts. No. SQLCMD would have to implement a full T-SQL parser itself in order to determine where the statement boundaries are. Whereas as it currently exists, all it has to do is find lines with "GO" on them. Determining statement boundaries can be quite tricky, given that ";" terminators are still optional for most statements. Hmmm, I guess this is not going to

sql scripting variable default value

情到浓时终转凉″ 提交于 2019-12-05 03:28:12
I have a script file e.g. test.sql. I want to call this from another script, say caller.sql, in sqlcmd mode using :r test.sql. This works fine, but I want to use a scripting variable in test.sql. When I call test.sql from caller.sql I can set the scripting variable and all is well. However, I want to use a default value for the scripting value so that if the caller does not set the variable, or if I run test.sql directly (not from caller.sql) then the scripting variable defaults to a set value. I have tried things such as begin try select '$(grip)' select 'grip value was found' end try begin

Exporting CSV data using SQLCMD.EXE

僤鯓⒐⒋嵵緔 提交于 2019-12-05 01:06:30
I'm trying to export data from SQL Server into CSV format. I have a bat task to do this that's run at regular intervals. Command is: SQLCMD.EXE -d [db details] -i c:\export.sql -o c:\export.csv -s"," -W The SQL file is just a SELECT * from a view. This works except that some of the rows have commas in the data, so the values need to be quoted. I could change the column separator to be "','", but then I'd need SQL Server to escape single quotes in the data as well. Unfortunately changing the separator to another character is unlikely to solve the problem in 100% of cases as one of the fields

passing path to SqlCmd within powershell script

会有一股神秘感。 提交于 2019-12-04 18:06:48
问题 I'm trying to write a powershell script which will execute sqlcmd.exe to run a sql script. The script contains a SQLCMD variable which I want to pass in on the command line via sqlcmd's -v switch. The problem is that powershell is doing something weird when I pass a path as the value of one of my variables which in turn causes the SQL script to fail. For example I'm calling: $path = 'C:\path' sqlcmd -SMySQLServerInstance -i 'MySqlScript.sql' -v MyVariablePath=$path when run I receive a error

Powershell SQLCMD

江枫思渺然 提交于 2019-12-04 15:32:32
We were experiencing problems with Powershell and SQLCMD, when there was sapces in the -v parameter variable powershell wouldn't run the command. e.g. sqlcmd ... -v VAR="Some space" Has anyone experienced this before or know how to fix the problem? Thanks, B The syntax above works for the PS commandline but fails within a script. We struggled a long time with how to make this work. One of our very clever QA guys finally came up with the following: $variableWithSpaces="one two three" $mySqlCmd = "sqlcmd -E -S $dbServer -i $script -v var=```"$variableWithSpaces```" " Invoke-Expression $mySqlCmd

SqlServer 08: Query to list all databases in an instance?

元气小坏坏 提交于 2019-12-04 15:32:01
问题 How do I list all the databases for a given sql server 08 instance using sqlcmd? 回答1: sqlcmd -E -S SERVER\INSTANCE -Q "sp_databases" 回答2: EXEC sp_databases or SELECT NAME FROM sys.sysdatabases or EXEC sp_msForEachDB 'PRINT ''?'''; 回答3: To elaborate with more detail for the sqlcmd newbie: C:\> sqlcmd -S <the_server_name> 1> select name from sys.databases 2> go 回答4: You can use sp_databases stored procedure. 来源: https://stackoverflow.com/questions/2087902/sqlserver-08-query-to-list-all