Please help I need to get rows in the 2 tables with the foreign key poiting to table_a as seen on picture. I have tried Joining this way, SELECT * FROM table_a INNER JOIN table_b ON table_a.id = …
SQL JOIN: add custom constraint in JOIN clause
I want to select the preferred language if it exists and the default language otherwise. SELECT a.code, case when vpi.program_items is not null then vpi.program_items else vpi2….
How to count all distinct rows?
If I have a table like below, how can I count and sum all distinct values? student_name | section | score | class ————-|———|——-|——- John | B | 32 | 8 Doe …
Can I rollback a transaction that has multiple inner transactions in SQL Server?
I hear if there are nested transactions, the inner transactions will not be committed. For example, I have a Parent Procedure and about a handful of children procedures each with begin tran/commit/…
SQL If else statement dealing with current time
I have this SQL that pulls exactly what I want, but I am missing the last piece. I need the SQL only to display information when the HRS is greater than 48hrs. I tried doing an if else statement but I …
Division by 0 in SQL Server
How to solve divide by zero problem? I am trying to calculate profit percentage but getting divide by zero error. I am new and tried all most all forum but couldn’t find any solution. I’m using SQL …
Balancing an environment monitor using SQL
I am working on something very specific so I’m hoping others have an idea of what approach might work. I’m trying to make it so a monitoring script that runs once every 5 minutes will not blast …
Querying a Many-to-Many Linking Table
I have a linking table for a many-to-many relationship, with the fields – idNote idTag I would like to filter for all the tags that are associated with the notes that contain a specified number of …
How do you normalize a table with a multi-valued field?
I want to normalize a staging table into two tables. One of the fields of input data contains multiple values delimited by a semicolon. DATETIME | FILENAME | MULTIVALUEDFIELD 7-22-18 | somefile.txt |…
SQL Server hierarchy, selecting parent nodes for distinct IDs
Stuck on this hierarchy problem, so here goes. I have the following hierarchy table, which has been truncated. The hierarchy has been joined to another table on the ‘codes’ column, with the following …