I have two tables like this: Table 1 – CivilOffices Table 2 – Offices I want to query all the offices with their respective parent office name. But when I tried to query this, the query returns the parent office id instead of parent office name. Here is the query I used. Here is the result Instead…
Tag: sql-server
What is the impact of altering a table and making an Identity column the Primary key?
I am fixing issues on a new database, set up by a third party. SIDE NOTE: I have just joined the company that originally hired the third party. The new database is less than two weeks old and was …
Unexpected NULLs in outer join
I have 3 tables I’m trying to join. Let’s call them TableA, TableB, and TableC: DECLARE @TableA TABLE ( Key1 int, PRIMARY KEY ( Key1 ) ) DECLARE @TableB TABLE ( Key1 int, …
Returning multiple columns from a table with no duplicates of one of the columns
I have a SQL Server table containing columns id and email (amongst others). The id column contains distinct values, the email column may contain duplicates. I can retrieve all the distinct email …
Returning id in generic insert using JOOQ
I have a very generic API to insert stuff using JOOQ to soem tables: Is there a way to return id of that inserted record? All primary keys of tables in my db are named “id” so I could ahrdcode it but I cannot find a way to return it and cast to Integer / Long. I’m using JOOQ 3.9.5.
Based on Condition Extract Values Right of String
I have a dataset in sql that looks like this: Col1 Col2 13_DND_ 5 _DND_ 6 123_ETL_ 10 ETL_ 12 DND_ 15 _ETL_ 17 If Col1 contains either _DND_ or …
SQL query to sort data while insert , first numbers then alphabets an last symbols
I am getting trouble to write SQL sort Query, I have table as follows And I want to sort above data as, First should number and then alphabets and last special symbols like following table. First …
SQL select the min and max values of the intersecting interval
In MsSQL 2014 I`ve got a table containing intervals of values Col1 Col2 1 3 2 4 7 12 7 15 14 21 I need to get the maximum and minimum values of the intersecting …
SQL Trigger throws error but still inserts
I am working on a trigger that is supposed to block an insert when @verkoperstatus is 0; this does function, but for some reason it also stops the insert when @verkoperstatus is 1. What could be the …
MS SQL : Need to get row wise value from cell for similar rows, Code not working correctly
I have 100s of excel sheets(CSV files) I need to use for the historical load. I am going to load all the CSVs to a stage table using ETL. I am trying to get the row-wise value from the cell for …