this is my data: id segment country product status month year 83916512 Government Null Null Null Null 2014 83916512 Null Germany Null Null Null 2014 83916512 Null Null Carretera Null Null 2014 83916512 Null Null Null completed Null 2014 83916512 Null Null Null Null June 2014 83916512 Null Null Null Null Null …
Tag: sql-server
SQL SERVER Replace Null
I have a tsql query like that: DECLARE @TABLE TABLE( id int primary key identity(1,1), code int ); INSERT INTO @TABLE VALUES (1),(NULL),(NULL),(NULL),(2),(NULL),(NULL),(NULL),(3),(NULL),(NULL)…
Get Max from a joined table
I write this script in SQL server And I want get the food name with the Max of order count From this Joined Table . I can get Max value correct but when I add FoodName is select It give me an error. …
How to include OPENJSON in View?
My JSON object is stored in the table (single cell). Right now, I’m reading the cell and saving the value to @json NVARCHAR(MAX) , but that obviously doesn’t work in views. How can I do something like this? Answer You can use cross apply to apply openjson() to each and every row of your table:
Merge Null Values in Merge Command
i must merge multible database tables in a node js windows service. so i decided to write a method that creates a sql string for this. here is my method: this method and the created sql string works nice, expect in one case. if the value in the source table column is NULL the target will not be updated. here
SQL. Comparing value from current row versus the value resulted from the same comparison of the previous row
I am trying to create a script that would compare and get the higher value from current row versus the value resulted from the same comparison of the previous row. For example: Row 2 Column ‘Given’ > Row 5 Column ‘Result’. Therefore, Row 2 Column ‘Result’ gets the same v…
Select data from multiple existing tables dynamically
I have tables “T1” in the database that are broken down by month of the form (table_082020, table_092020, table_102020). Each contains several million records. There is a second table “T2” that stores a reference to the primary key of the first one and actually to the table itself only…
Best way to find cancel and substitute match from the table
I have a table which has all order information. Id is the unique key for the table and it’s grouped by Order_Id (every order for the same product has the same Order_Id). The main thing is that if order is cancelled, it is recorded as a cancelled order (Cancelled? = True) and for following orders, it mus…
Rolling Sum for Last 12 Months in SQL
I’m trying to get the rolling sum for the past 12 months (Oct 2019-Sept 2020, etc.)> So far, I figured out to get the current year total (which I also want), however, I’m stuck on a legit 12 month rolling sum. here’s what my current output looks like AS you can see, it resets at the begin…
How to find missing data in table Sql
This is similar to How to find missing data rows using SQL? and How to find missing rows (dates) in a mysql table? but a bit more complex, so I’m hitting a wall. I have a data table with the noted Primary key: I have a products table with all products, a countries table, and a calendar table with all