I have the a stored procedure to generate an XML document based on the UBL-TR-2.1 standard. This is the query where the xml data is generated: A sample output of this query is this XML file: This works so far so good. But now some XML elements shall have attribute in the element itself. One example is: How ca…
Tag: sql
Why does SQL Server read uncommitted data when the default isolation level is READ COMMITTED?
You have a dbo.inventory table and the itemsInStock is 10. Let’s say you run this query: (and you don’t commit the transaction) Why is SQL Server reading a 5 if it hasn’t been committed yet and the default isolation is read committed? Answer Obviously a transaction needs to see everything it…
Get room members, room’s owner and admin at the same time in one query with grouped by id (unique) on PostgreSQL 12
I want to get room’s member list, room’s owner member in case of he doesn’t exists in other table and admin member at the same time. Currently i fetch them individually. CREATE TABLE public….
SQL – create SQL to join lists
I have the following table: Add Data: Find users who share addresses. Expected Results: Question: How do I formulate a SQL query to obtain the expected result? Much appreciated. More info: PostgreSQL 9.5.19 Answer I don’t know if this is the most efficient method, but I can’t come up with somethin…
Find start date and end date from the employee time clock
I am trying to find out star date and end date for the employee time clock. Following is the example of the data I have. Output wanted: I have to find the start date and end date of the person based on eventtime and activitycode. The start date will be event time column and I have to calculate end date
Finding an ID not in another column
I’m working on a little SQL exercise, and am scratching my head an this problem. I am trying to find all the Employees to whom no other employee reports to. This is what the employees table looks …
SQL change a table into another format
I have a table like this: Faculty Program Number_of_enrolled Science Financial Modelling 25 Science Actuarial Science 30 Science Statistics 28 Science Biology …
Row lumping, cycle dates
I want to look at the lead type and if that type is the same for that row then merge in those dates to fit within one row. I have the below table: Expected Results: How can I get my output to look like the expected results? I have tested withlead lag rank and case expression but nothing worthy of
SQL to pivot a field with CASE WHEN
My table has fields: Item, AttributeNo_, AttrbuteValue. Each AttributeNo_ has a matched AttributeName. e.g. Item, AttributeNo_, AttributeValue A, 1, Yellow A, 2, Round …… …
Stuck on final SQL query
I’m busy creating a report and am stuck with how to structure the final query. I have a sub-query that returns the following result set I need the final query result to look like this: I know I can …