I have a sql query if my filter date is > 20210625 , I get value as 27 and previous value as null , is it possible to get the prev_value 25. If there is no filter I will get it. But filter is required to prevent reading the whole table. Also one more requirement. If previous value is null
Tag: sql-server
Using HAVING COUNT(column name) NOT working as expected
I have the SQL statement, working in SQL Server 2016, below where I’m getting records from an INNER SELECT UNION ALL statement and in the OUTER SELECT I’m trying to extract those records that meet the HAVING COUNT code however, my code is bringing back no records. Here are the records from my INNE…
How can I compare rows of two similar tables in SQL?
These TSQL tables are exact but I can’t guarantee that. I cannot guarantee which rows will be non-existent in either table. What I want to be able to do is to subtract one from the other into a new table. For instance, “Agg Asslt” should have a column value for “OffenseCount” of …
Getting empty result from a query
I have Client table ClientGuid Email Phone Also have Activity table ActivityTitle Date ClientGuid If client does some “Activity” it is saved in Activity table. I want to get Emails of clients who did not have any activity in last three months and had activities before. Tried this : Getting empty r…
How to write sql query to get this result
I had two tables as below: request_id update_from_id sw_ref_number raised_by_user_id raised_date 1 0 1 3 2019-08-29 15:08:16.000 id request_id input_id value is_deleted 21 1 1 00001 0 22 1 2 3 0 75 2 1 00002 0 76 2 2 0 My query is: And after that my result is: request_id sw_ref_number value input_id 1 1 00001…
Pulling out monthly daypart data
I’m dealing with sales data that looks like this Date Time Net Amount Store No Item Category Code 2021-03-21 00:00:00.000 1754-01-01 08:01:14.627 100 001 FOOD 2021-01-31 00:00:00.000 1754-01-01 15:42:21.670 120 002 FOOD 2021-04-24 00:00:00.000 1754-01-01 17:35:30.070 160 002 FOOD 2021-03-14 00:00:00.000…
Power BI Report Builder Indicator Formula
I am adding in an indicator to a PBI Report Builder Report. The indicator is based off multiple fields from the dataset so I need to use a formula, to create the three up/down/side arrows. Previously in Crystal Reports this could be implemented using a series of IF statements as follows. The below example is …
Select last value in each group
In database I have two table. I want to join two tables and get last row each SensorType Sensors table: Id CodeNumber PortNumber SensorType IsActive 13 Dht11 3 0 1 14 Dht11 3 2 1 17 Global 100 4 1 18 Dht11 3 1 1 19 Dht11 3 3 1 SensorsValue table (SensorId is foreign key Sensors table): Id SensorId
VBA ADODB error (80040e14) when trying to retrieve data from SQL Server
I am trying to connect to SQL Server from Excel VBA using the following code and with some specific simple queries it actually works like a charm. My problem shows up whenever I try to run the query right below to which I get the following error: ‘-2147217900 (80040e14)’ An expression of non-boole…
Convert multiple rows into single row with more columns
I have a SQL Server table of properties related by an id and want to do a query to check if an id has a set of properties. Basically I want to do a transform as follows, grouping by the Id and adding a column for each unique property: Starting table: Id Prop Value 1 P1 V1 1 P2 V2