Asked for the logic yesterday, now I’ve worked a way around. I have a big table used for reporting (170k~ rows) and many of them are “duplicated” but with updated dates (e.g. old record says John Doe …
Tag: sql-server
Use time selector from Power BI as an argument in my SQL query
I have a simple query like : SELECT COUNT(DISTINCT(p.id_organization)) AS Count FROM dbo.paiement p WHERE p.statut = ‘AUTHORIZED’ AND p.[date] > ‘2018-01-30’ I try to show this data on a …
Identify rows with particular value across multiple columns
Each row has an Id and a Category Presence/Status combo. Sample code: DECLARE @sample_table TABLE ( Id INT ,Category_Alpha BIT ,Category_Beta BIT ,Category_Charlie BIT ,…
How to join two tables based on FIRST VALUE of a group
Objective: I would like to join two tables based on the first value of Id column grouped by subscription Id column ordered by created_at column. Situation: Table1 looks like this: id channel …
How to Run Two T-Sql Statement By Exec Command in SqlServer?
I want run 2 SQL queries in Exec instruction, how can I do this? ListOfLeaveRemainingInfo is a user-defined table type: When I run the stored procedure, I get this error: Msg 1087, Level 15, State 2, Line 33 Must declare the table variable “@LeaveRemainingTempTable” Answer Scratch the previous. @L…
SQL Joins for Multiple Fields with Null Values
I have a table of maintenance requirements and associated monthly frequency it is to be performed maint I also have a table of equipment with data on its manufacturer, model, device type and building. equip I am trying to match each maintenance requirement with its associated equipment. Each requirement appli…
Adding three Integer variable shows result as Null, why?
Here is the code I tried SELECT case when InsertedRows is null then 0 else InsertedRows end InsertedRows ,case when FailedRows is null then 0 else FailedRows end FailedRows ,case when UpdatedRows …
Finding line and position of text in string
I need to get de line number and position (on that line) of a specific word in a text. For example: — This is my first line. This is my second line. — If I would check for ‘second’ I should get …
SQL Error 4104 : The multi-part identifier could not be bound
I’m developing a project in which I have to use a database to store data from a cinema. One of the tables stores some movies data(movie name, duration actors, etc) and it has a image column; I left it …
One select statement with multiple Group BY on the same column
I have ‘TABLE_A’ like this: TVA Amount InvoiceID ———————- 22 | 10.00 | inv-12 22 |-14.00 | inv-13 25 | 24.00 | inv-14 25 |-36.00 | inv-15 25 |-25.00 | inv-16 25 | 18.50 | inv-…