Skip to content
Advertisement

Tag: sql-server

Trigger to create or update records in another table

Edit: This question is mostly solved. What I am still trying to do might require a different approach. I am adding a trigger to a legacy database table, in order to automatically create new records for a related table. This is not homework. Here is my DB Fiddle on SQL Server 2017. https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=ed2ed585606da9d69cb63402ea5c0807 For example, here is what the parent

Check if procedure exists in any database SQL Server

I’d like to know if there is any way to search for a procedure in all the databases of a server (there are only SQL Server databases on that server). So far I’ve only found how to find a stored procedure in a certain database with Object_id(), but it would take too long for me to manually search each database

SQL Server: How to flatten nested arrays by merging values using

I have 10000 jsons with different ids each has 10000 names. How to flatten nested arrays by merging values usin SQL Server? Jsons can be read in any language, I’m looking for any SQL dialect that can transform the data as I’m using spark connectors. I use many SQL dialects including not limiting Spark SQL, Postgresql,MySql, SQLite and SQL Server…

How to group by two columns in different CASE clauses

I have a query that’s giving me the results I want, but for each item with a given ID_UNIDAD_EXPERIMENTAL there are two rows, one with column “Alt” with a value and column “Dap” with null, and the other one with “Alt” null and “Dap” with a value. My question is: How can I group them so each element with a

How to update several tables with a result query?

I am working with SQL Server 2017, and I need to clean up duplicate rows and update all rows in other tables that contain my field. I’ve got one table which contains my customers Then I have 7 tables that contains the userid column and 1 table with another name column My other tables: I want to clean the duplicates

Sql Query To Sum Amount Before the Date And After Between Dates

I am looking for a SQL query to sum the amount before the date and after between dates. I have the following table in my database. Now what I want to find out is the total sum (DebitAmount) – Sum (CreditAmount) that is before 2021 and then from 2021-01-01 to 2021-03-01: Table Script The Query I Have tried The Result

Bring a row for each specific column that is not empty, with the column name

I’ve this table with the following data: ID Data1 Data2 Data3 Data4 Data5 Data6 RandomInformation 1 Test1 Test2 Test3 Information1 2 Test5 Test6 Test7 Information2 3 Test8 Test9 Test10 Test11 Information3 The resultant table i want should be as below: ID Data RandomInformation 1 Data1 Information1 1 Data3 Information1 1 Data5 Information1 2 Data2 Information2 2 Data4 Information2 2 Data6

Advertisement