Archive for March, 2017

Get Row Count of Insert/Update/Delete records in MERGE Statement – MSDN TSQL forum

March 29, 2017 Leave a comment

–> Question:

How can I get the numbers of records affected in the Merge statement, INSERT,UPDATE,DELETE separately and store it in a variable so I can get it in the application side?

Thanks !

–> My Answer:

You need to use OUTPUT clause with MERGE statement, try this:

DECLARE @SummaryOfChanges TABLE(Change VARCHAR(20));

MERGE tblTarget AS Target
USING (SELECT Col1,Col2 FROM tblSource) AS Source
ON (Target.Col1 = Source.Col1)

	UPDATE SET target.Col2 = source.Col2 -- Need to get affected rows here

	INSERT (Col1,Col2) VALUES (Col1,Col2); -- Need to get affected rows here

OUTPUT $action INTO @SummaryOfChanges; --< check here

-- Get the count of Insert/Update/Delete'd records from the below table variable
SELECT Change, COUNT(*) AS CountPerChange
FROM @SummaryOfChanges
GROUP BY Change;

For more info on MERGE and OUTPUT clause statement check this link:

Categories: SQL Tips Tags: ,

SSDT – OLE DB or ODBC error: Login failed for user ‘DOMAIN\ComputerName $’ 28000

March 23, 2017 Leave a comment

My colleague was working on a Tabular Model project and while working with the Tables so that they can be deployed to the Cube on Analysis Server, he was getting a weird error. The authentication was failing and in error message it was showing the computer name instead of his actual user name, suffixed with a $ sign.

Failed to save modifications to the server.
Error returned: ‘OLE DB or ODBC error: Login failed for user ‘DOMAIN\ComputerName$‘.; 28000.
A connection could not be made to the data source with the name of ‘CubeConnectionName’.


By looking at the above error it seemed that somewhere the authentication is being overridden by some setting. So after some research I found that in Data Source section there is Impersonation setting which can be set to a specific user, service account, current user or an unattended account.

–> Here is the resolution:

1. On Tabular Model Explorer go to the Project and expand Data Sources.

2. Here right click on the connection and click on Edit Data Source, or just double click on it.

3. Click on the Impersonation… button and check what option is selected.

… I found that the selection was defaulted to Service Account, and as my SSAS (Analysis Services) was running under the DOMAIN\ComputerName account which gets sets while installing SSAS. And as it does not have sufficient privileges or access rights, it fails to connect to the Database Server. Thus you need to check impersonation and provide an account which has access to the Database Server.

4. Change the selection from “Service Account” to “Specific Windows user name and password”, and apply the user name and password.

5. Click OK and Save the settings.

6. Now go again to the Table Properties and click on Refresh Preview button and click OK.


Categories: Uncategorized