All Questions
8 questions
0
votes
0
answers
715
views
SSMS path error: file specified for :r command was not found
While navigating to the given path on cmd it was working fine but I am not sure why its not working here.
:setvar path "C:\Users\hamid\Documents"
IF NOT EXISTS (SELECT * FROM ...
0
votes
2
answers
1k
views
Connect to multiple servers and databases and run the same SQL statements
I have a fixed list of SQL Server 2019 (v15) Express databases, distributed across the country. I am hoping to script a way of querying them in a T-SQL batch. Have gotten as far as enabling SQLCMD and ...
0
votes
1
answer
199
views
SQL Query fails while running in SQLCMD Mode
I need help, I am writing the SQL code shown below for extracting data from multiple servers from the SSMS window of one SQL Server. I have CMC on SERVER1 and have registered SERVER2 as well and all ...
1
vote
1
answer
413
views
Connect to multiple DB's from different servers
I have multiple DB's on different servers and I want to take some information from a table (for example User- this table is on all DB's). So I add all servers and DB's on a cursor and then I run this ...
0
votes
0
answers
395
views
SQL variables and the IF statement
I am using T-SQL in SQLCMD mode in SSMS to run various subfile from one file, and the principle file (princ.sql) is where I need to declared and set a variable @MyInteger and run a subfile:
DECLARE @...
0
votes
2
answers
1k
views
How to display the error message when using ":on error exit" in SQLCMD mode?
I have a query with T-SQL statements in SQL Server 2012 with SQLCMD Mode turned On running interactively in SSMS. There's a :on error exit statement. When I run the query, the query window shows "...
3
votes
2
answers
10k
views
SQLCMD mode: Environment variable syntax
I assume the best way to set my SSMS output file path during runtime of T-SQL, is to use SQLCMD mode.
How do I use environment variables (e.g. %systemroot%) in the code? The following bombs:
:set ...
2
votes
2
answers
3k
views
SSMS in SQLCMD mode - Incorrect Syntax
It is my day for weird errors.
I use a database project and as a part of Post Deployment, we use SQL Scripts to populate data in our tables.
alter authorization on database::atlas to sa;
go
ALTER ...