I would like to make a GROUP BY CUBE of a table with 9 columns and more than 107 millions of rows. Here is an example of my code: This is running in SQL Server. For 10K rows it is taking 7 seconds, but when I increase the number of rows to the total 107 million it took more than
Tag: sql-server
Search data based on two columns SQL
I have a database table like this: I need search from Id the Id’s that not have Tipo = Inventario and Create a new line with that data, I mean for example, RTOR-00261 and RTOR-0255 dont have INVENTARIO, I need to create new with the fields that there is in SUSTRATO. All data are in the same table Final …
Creating a Pivot Table in SQL
I could use some help with creating a PIVOT table. The table that I’m looking to pivot from is: Where I want to change it into the Format of Which has the tracking number as the Row Identifier, the added columns are the Unique Values in the ‘Surcharge Reason’ column, and the values of the da…
SQL bring number of count, another column basis problem [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I have this table: BANK – BRANCH_NAME – ADDRESS – DISTRICT – CITY &#…
Improve pivot view performance
I have a key-value structure for storing dynamic entities (standard EAV). I made a view for this Entity with the Pivot command. I tried to set the index for this view, but it is not possible due to the use of pivot. Is there a way to drag my data into SQL at the time of insert, Update? Because performance
Fill in missing dates and grouping problem
I have a table with Case records with CaseId, UserId, Opened date, Closed date etc value. For reporting I need to have a result table with all users by continuous months with number of case still …
UNION two tables with conditions from the first
I have a union on the same table [MyTable] so I can select certain values as the top 5, the logic of which I’m excluding here to simplify the question (I hope): The first table I alias as tbl1 – can I reference this alias somehow after the UNION statement so that I can exclude the results from it?…
Update next record based on last updated record
I’m struggling to find a solution to update the calculation in the same table based on last updated records order by select column. I have tried LEAD & LAG, but can’t give complete solution of my problem. I tried below query but didn’t succeed. I can use a while loop, but there are more …
Assign a value to a column based on multiple conditions
I have accounting data in SQL. These are entries made for a sale so for every sale made there is an offsetting entry for cost of goods sold as well. In the accounting system we use, it auto generates a transaction id in the TxnId column only for the sales lines not for the cost of goods sold lines for
Passing string of parameters to stored procedure
I have a stored procedure that needs to accept a parameter @pnumber as a string of values like 1001,1002,1003… My stored procedure looks like this: My data: The problem with this stored procedure is – when I input the parameter as (1001,1002) the query produced looks like this: My query should act…