I have invoices pending payment, every invoice has two dates, first when the invoice is required to pay and the other when the invoice is paid. I want to know in a period of time the max debt and the …
Grouping shift data by 7-day windows in SQL Server 2012
What I want to do is to calculate the number of shifts and hours worked by each employee in any given 7-day period. In order to achieve this, I need to identify and group ‘islands’ of shifts. Note …
SQL count products
I have table: name product john beer john milk john tea john beer emily milk emily milk emily tea john beer i need select from this table, when output will be: name …
Assign new value to every unique number in SQL Server
I am new to SQL Server and trying to do some operations Sample data: Amount | BillID ——-+——- 500 | 10009 500 | 1492 350 | 15892 222 | 15596 899 | 20566 350 | 9566 How can …
Compare SQL scalar function result to a column in SQL
I have this query Here I need to compare the result of function i.e dbo.GetTopEmployerName() with x4.code. I need to check if they are not same. Answer Wrap your query up in a derived table:
Specific hierarchy geography
I have a table geography with three levels I need to display the level3 only for level2 = France, Benelux and for the other countries level2 = level 3 Result Example: Answer
How to convert this Entity Framework query to a SQL Server query
I have a query which is written in format like this: How do I convert this query to a plain SQL Server query to see what its output is? Answer In Entity Framework there are a few ways to look at the SQL a query generates. Note: All these ways will use this query: Cast IQueryable to an ObjectQuery and
How to copy all records and add some changes in the same table in OracleDB
I would like to copy all records into the same table with some changes. Is someone tell me a good way? I tried to this. but Not Ended error happen. How can I fixt it? ORA-00933:”SQL command not properly ended” 00933. 00000 – “SQL command not properly ended” *Cause: *Action: Answe…
Postgresql Convert SQL XML Coding to SQL JSON Coding
How to convert XML SQL Coding to JSON SQL Coding. Example: SELECT XMLELEMENT(NAME “ORDER”, XMLFOREST(PURCHASE_ORDER AS OD_NO)) AS “XMLELEMENT” FROM TBL_SALES Now how to convert …
SQL – Postgres string agg is giving duplicates
Im trying to collect the foreign key mapping from system tables. And I used this below query. query 1: But this won’t provide the Primary tables columns that are pointing as Fk. So I found this query on Stackoverflow. query 2 Now this query gives individual columns. Lets say there is a FK like (logid, i…