sqlcmd

Using sqlcmd with FOR XML returns Invalid Object name 'dbo.Table' yet Query runs in SSMS

…衆ロ難τιáo~ 提交于 2019-12-07 17:33:59
问题 This is my query: SELECT title1, [precinct percent] AS [PrecinctPercent], leader, [leader percent] AS [LeaderPercent], Winner, WinningVotes, leader2, [leader2 percent] AS [Leader2Percent], Loser, LosingVotes FROM [leader].dbo.[RACE] r inner join (select rc.[race number], max(case when seqnum = 1 then [candidate num] end) as Winner, max(case when seqnum = 1 then Votes end) as WinningVotes, max(case when seqnum = 2 then [candidate num] end) as Loser, max(case when seqnum = 2 then Votes end) as

How do I name the output textfile to YYYYMMDD based on the system date?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 14:31:19
问题 How do I name the output textfile to YYYYMMDD based on the system date? sqlcmd -S DataBBB -i c:\scripts\followup.sql -o %DATE:~4,2%_%DATE:~7,2%_%DATE:~-4%.txt -s ; -W -u Now the output text file is 01_31_2012.txt . How can I change it to 2012_01_31.txt ? 回答1: Tried it under Windows 7 Premium (German), may be dependent upon OS and Local Time Format. sqlcmd -S DataBBB -i c:\scripts\followup.sql -o %date:~-4%_%date:~3,2%_%date:~0,2%.txt -s; You have to edit this part for your system %date:~-4%_

Which user account is running SQLCMD in T-SQL Script without -U and -P option?

半城伤御伤魂 提交于 2019-12-07 08:20:31
I am using sqlcmd in a T-SQl script to write a text file to a network location. However SQLCMD is failing to write to that location due to access permission to the network folder. SP is being run under my user account which has access to the network folder. Could you please help me under which account sqlcmd will run if I do not specify -U and -P option in TSQL Script? Rashini Nanayakkara Use this to find the user name: PRINT Suser_Sname(); If you don't provide credentials with -u/-p it will try to use windows authentication; i.e the windows account of whomever is running it. I often just use

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

为君一笑 提交于 2019-12-07 06:21:39
问题 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. 回答1: 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

SQL72007: The syntax check failed 'Unexpected end of file occurred.' in batch near :

断了今生、忘了曾经 提交于 2019-12-06 21:31:59
问题 In SSDT project (using VS2017/VS2015, SSDT version 15.1.61702.140), I cannot get my project to build. The compiler keeps complaining about the sql statement in my PostDeploymentScript (yes, I have set the BuildAction property to PostDeploy). The sql statement is: if ('$(env)' = 'dvp') BEGIN PRINT 'creating users for dvp' :r .\SecurityAdditions\usersdvp.sql END ELSE IF ('$(env)' = 'qat') BEGIN PRINT 'creating users for qat' :r .\SecurityAdditions\usersqat.sql END The actual error message is: D

sqlcmd - How to display all the set option setting values

ⅰ亾dé卋堺 提交于 2019-12-06 14:50:18
问题 What is the command in sqlcmd to show all the set options and their associated settings? For example how do you show the current value for nocount? set set nocount set nocount ? 回答1: Determining SET Options for a Current Session in SQL Server DECLARE @options INT SELECT @options = @@OPTIONS PRINT @options IF ( (1 & @options) = 1 ) PRINT 'DISABLE_DEF_CNST_CHK' IF ( (2 & @options) = 2 ) PRINT 'IMPLICIT_TRANSACTIONS' IF ( (4 & @options) = 4 ) PRINT 'CURSOR_CLOSE_ON_COMMIT' IF ( (8 & @options) =

Powershell SQLCMD

怎甘沉沦 提交于 2019-12-06 11:43:58
问题 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 回答1: 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"

Remote Informix 11.5 Command Line Client

不羁岁月 提交于 2019-12-06 11:19:15
Does a command line tool ship with Informix 11.5 similar to SQLCMD for SQL Server? If yes, how do I connect to a remote server and perform regular SELECT/INSERT/UPDATE queries using it? As Michal Niklas says, the standard tool provided with IBM Informix Dynamic Server (colloquially IDS or even just Informix) is DB-Access. However, it is distributed only with IDS itself, not with the Informix Client SDK (CSDK) or Informix Connect (I-Connect) products. If you want to access IDS from a machine that does not have IDS installed, you need either CSDK or I-Connect on the machine, and some other

Using sqlcmd with FOR XML returns Invalid Object name 'dbo.Table' yet Query runs in SSMS

…衆ロ難τιáo~ 提交于 2019-12-06 03:29:24
This is my query: SELECT title1, [precinct percent] AS [PrecinctPercent], leader, [leader percent] AS [LeaderPercent], Winner, WinningVotes, leader2, [leader2 percent] AS [Leader2Percent], Loser, LosingVotes FROM [leader].dbo.[RACE] r inner join (select rc.[race number], max(case when seqnum = 1 then [candidate num] end) as Winner, max(case when seqnum = 1 then Votes end) as WinningVotes, max(case when seqnum = 2 then [candidate num] end) as Loser, max(case when seqnum = 2 then Votes end) as LosingVotes from (select rc.*, row_number() over (partition by rc.[race number] order by votes desc) as

How do I name the output textfile to YYYYMMDD based on the system date?

寵の児 提交于 2019-12-06 03:06:38
How do I name the output textfile to YYYYMMDD based on the system date? sqlcmd -S DataBBB -i c:\scripts\followup.sql -o %DATE:~4,2%_%DATE:~7,2%_%DATE:~-4%.txt -s ; -W -u Now the output text file is 01_31_2012.txt . How can I change it to 2012_01_31.txt ? Andreas Rohde Tried it under Windows 7 Premium (German), may be dependent upon OS and Local Time Format. sqlcmd -S DataBBB -i c:\scripts\followup.sql -o %date:~-4%_%date:~3,2%_%date:~0,2%.txt -s; You have to edit this part for your system %date:~-4%_%date:~3,2%_%date:~0,2%.txt The statement used the command line internal %date% - variable with