Context I’m using Microsoft SQL Server 2016. There is a database table “Raw_data”, that contains the status of a machine, together with it’s starting time. There are several machines and …
Tag: sql-server
c# ef core RemoveRange contraint violation
Hi I have a complex db with many tables and relations what we want to do is to copy all tables from a database to another but only taking rows starting from one table (salesorder) and going down following relations. So I avoided the .Include, and use IQueryable queries (one for each table) there is no problem…
SQL – How to avoid inserting duplicate rows from another table while matching multiple columns
Using Microsoft SSMS. There are two tables Table1 ID | SessionId | Handle | StartDate | ——————————— 1 | abcd | handle1 | 2020-08-01 00:00:00| 2 | abcd | …
Update table with using NEWID() function
In general, I would update a table randomly like the following scripts. However, I get some issue. It would update more/less then 2 rows. I try execute the following scripts many times for debug. The results are not always only two records. If I remove the order by newid(), the number of output result will be…
Get First Record of Each Group
First I would like to apologize if it is a basic question. So, i have monitoring data being stored every 5 seconds. I want create a query that returns me the first record every 10 minutes, for example:…
join of two queries missing values
I need help joining these two queries. Here’s the first dataset with its query: : and second: : My query produces this result: I need to return as I can’t figure out why my query is leaving out the records with no Inbound data. I believe a right join is correct. It seems like an issue with using t…
While updating table1, how do I INSERT to table2 for every change in table 1?
I have a MEMBER table and NOTIFICATION table. On client side, I list all of the records in MEMBER table and there is a points column and this is shown as text input. So after I change the values for some members, I can click save button and this will update the records in my MEMBER table that’s all righ…
Return a 0 if no rows are found in Microsoft SQL Server
I need your help with this query. My table CSO_EMP_ORG_DPM_VIE has a column with different keys. Column name is EXT_KEY. When I receive the same key number in EXT_KEY, I want the SQL code to count the duplicates using this query: This is working so far, but when it has no duplicate keys (numbers) in the colum…
Split data in column based on value of in another column
I have a table full of Artist and Track Titles that is imported from two different places. Some are correct with Artist and Title in different columns but then there are other rows where everything is in the Title column separated with ‘-‘ and the Artist column is NULL. Changing it at the source i…
How to query SQL Server Agent – all jobs’s error message result set
Question: how to query SQL Server Agent – all jobs’ error message result set Input: Expected result: What I’ve tried & know: I know Job Activity Monitor GUI form can do it, but it only contains last run as shown in this screenshot: Answer I searched msdn and found dbo.sysjobhistory (Tran…