SQL MERGE statement to update data

Assuming you want an actual SQL Server MERGE statement: MERGE INTO dbo.energydata WITH (HOLDLOCK) AS target USING dbo.temp_energydata AS source ON target.webmeterID = source.webmeterID AND target.DateTime = source.DateTime WHEN MATCHED THEN UPDATE SET target.kWh = source.kWh WHEN NOT MATCHED BY TARGET THEN INSERT (webmeterID, DateTime, kWh) VALUES (source.webmeterID, source.DateTime, source.kWh); If you also want to … Read more

Sql Server ‘Saving changes is not permitted’ error ► Prevent saving changes that require table re-creation

From Save (Not Permitted) Dialog Box on MSDN : The Save (Not Permitted) dialog box warns you that saving changes is not permitted because the changes you have made require the listed tables to be dropped and re-created. The following actions might require a table to be re-created: Adding a new column to the middle … Read more

Enable ‘xp_cmdshell’ SQL Server

You need to enable it. Check out the Permission section of the xp_cmdshell MSDN docs: http://msdn.microsoft.com/en-us/library/ms190693.aspx: — To allow advanced options to be changed. EXEC sp_configure ‘show advanced options’, 1 GO — To update the currently configured value for advanced options. RECONFIGURE GO — To enable the feature. EXEC sp_configure ‘xp_cmdshell’, 1 GO — To … Read more

SQL group_concat function in SQL Server [duplicate]

FOR XML PATH trick and article CLR User defined aggregate for sql server prior version 2005 – temporary tables An example of #1 DECLARE @t TABLE (EmpId INT, EmpName VARCHAR(100)) INSERT @t VALUES (1, ‘Mary’),(1, ‘John’),(1, ‘Sam’),(2, ‘Alaina’),(2, ‘Edward’) SELECT distinct EmpId, ( SELECT EmpName+’,’ FROM @t t2 WHERE t2.EmpId = t1.EmpId FOR XML PATH(”) … Read more