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
Tag: sql-server
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
Compare COUNT results before and after operation/load in SQL
I need help for one of my cases. Lets say that I have one table with only one column named CustomerID with 1500 records. The CustomerID table is loaded in DB 2 times per day – 10am and 10pm I want to compare the CustomerID table in the morning (10am) with the one in (10pm) SELECT COUNT(*) from CustomerID —
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…
Compare table column with a range of values and take the position of that value from another table
I got stuck with this problem, please help if possible. Suppose we have two tables, Table A and Table B. Table A looks like this: And Table B looks like this: In table B we have around 23 values for each date, now we need to match val1 of table A to val2 of tableB for each date and return
Conversion failed when converting the varchar value ‘ AND ID =’ to data type int
I was looking how I can parameterize table names and so I found dynamic sql queries. I finally got the proc saved, but when I execute it errors out with “Conversion failed when converting the varchar value ‘ AND ID =’ to data type int.” I have no idea what is going wrong when I try to execute this stored
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