[Solved] Cummulative SUM based on columns

No need to make thinks more complicated than they need to be… IF OBJECT_ID(‘tempdb..#TestData’, ‘U’) IS NOT NULL DROP TABLE #TestData; CREATE TABLE #TestData ( ID INT NOT NULL, [Year] INT NOT NULL ); INSERT #TestData (ID, Year) VALUES (1, 2010), (1, 2010), (2, 2010), (2, 2011), (3, 2012), (4, 2013), (5, 2014), (5, 2014), … Read more

[Solved] Copy database to a new server

Follow this steps : Run your SSMS Right click on the database you want to copy In the Popup menu , go to Taches , then click Offline Right click on the Database again in the popup menu , Taches -> Detach Open the folder ..\MSSQL\DATA , copy Yourdb.MDF and YourDB_log.LDF files to the folder … Read more

[Solved] How to convert comma separated value into rows in sql server

You have tagged your question with SQL Server 2016, in SQL Server 2016 there is a new function STRING_SPLIT. In SQL Server 2016 your query should be as simple as: declare @tab table ([user_name] varchar(10),Unit varchar(100)) insert into @tab VALUES (‘ABC’,’1,2′) SELECT t.[user_name] , Value as Unit FROM @tab t CROSS APPLY STRING_SPLIT(t.Unit , ‘,’) … Read more