Skip to content

Tag: sql-server

Custom Week Number SQL

I need to convert the following logic to python and SQL (SQL query is more imp): I have a table with ID and Date columns. I need to add a column called “Week_Num” such that: Every time it sees a new ID, Week_Num becomes 1 7 dates correspond to 1 week so if the first week begins on 29th Oct

Need help in framing SQL Query

TABLE-1 OrderDate CustomerNo ProductId Quantity 2021-03-01 1 1 10 2021-03-01 1 3 20 2021-03-02 1 2 15 2021-03-02 1 3 10 2021-03-03 1 1 10 2021-03-03 1 5 25 This table also contains data for other customers also Customers 2,3,4 … TABLE-2 ProductId ProductName 1 P1 2 P2 3 P3 4 P4 5 P5 Products are not Fix…

Unable to Query XML Document with SQL/OPENXML

I would like to query the following XML-File using SQL: Using this code I would like to get the value for “mRID”: However, the result is: mRID NULL How to get the correct value for mRID (‘2f6f8b82348440b1b121bca06311945d’) instead of NULL? Answer Microsoft proprietary OPENXML and its c…

Performing subtraction in SQL/finding the balance

SQL table here: http://sqlfiddle.com/#!9/abe1da/9 Current Table: Year Month Type Accounts Amount 2021 1 Actual abc 20 2021 1 Actual def 30 2021 1 Actual ghi 40 2021 1 Actual X 7 2021 1 Actual Y 3 2021 1 Actual final 105 Expected Year Month Type Accounts Amount 2021 1 Actual abc 20 2021 1 Actual def 30 2021 1 …