0

Stemming from this post: Powershell: Specify file path as variable

I am using Invoke-Sqlcmd in a PowerShell script to execute the following sql query:

update [$Db_name].[dbo].[$BatchTable]
set [$Db_name].[dbo].[$BatchTable].Wave = 'Wave1'
from [$Db_name].[dbo].[$BatchTable]
inner join OPENROWSET(BULK '$FILEPATH',    
FORMATFILE= 'C:\import.xml') AS a
on ([$Db_name].[dbo].[$BatchTable].Name= a.Name) and  
([$Db_name].[dbo].[$BatchTable].Domain = a.Domain)

I am logging a few messages but I am wondering how I can log any errors when the update query is run as well as when a match is found (optimally display a count successful and unsuccessful matches)

2
  • Are you looking to log SQL errors or PowerShell errors? Commented Apr 30, 2015 at 0:42
  • I am looking to log SQL error Commented Apr 30, 2015 at 1:31

1 Answer 1

1

The MSDN documentation mentions that you could use the -OutputSqlErrors command line parameter with Invoke-Sqlcmd to display errors encountered while executing the SQL command.

EDIT: This SO post might also be helpful to you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.