I have two tables emails and blockedSender I am trying to remove blocked sender from the email query. e.g. emails table: user_id from_address 1 name-1 <email-1@address.com> 2 name-2 <email-2@address.com> blockedSender table: blocked_address email-1@address.com Here I want to return all elements from the emails table where the from_address does not do a LIKE match with entries in the blocked address. Something
Tag: sql-server-2008-r2
Apply multiple count conditionally in SQL Server query
I have a task table which contains some DateTime type columns like completed, pending, exception. It joins user table and I want to bring userName, AllTaskCount, AllPendingTaskCount, …
Pivoting a dynamic column based on split value
I Have a couple of tables as per below Position table Id PositionName 1 Developer 2 Analyst 3 Tester Employee table Id Name Positions 1 John 1,2 2 Lisa 3 3 Smith 1 4 Willow NULL 5 Burly 2,3 …
SQL Server 2008 R2 split one row of results into two rows
In simple terms the table (t1) looks like this: I’d like to get results from the table that looks like this: Thanks Answer You may try simple query, using operator Union:
SQL Group by date with multiple same results
How to write a statement that groups data by date but shows when data changed for the first time date – when data changed a,b,c – some data and it can be anything This is should be the result. It might have the same data on different dates, but it missing the next day when data stayed the same. It
High performance query to get datetime when value was last changed
The data I am working with Consider the following 2 database tables: CREATE TABLE [dbo].[Contact]( [ID] [int] IDENTITY(1,1) NOT NULL, [Contact_UID] [uniqueidentifier] NOT NULL CONSTRAINT […
SELECT Records From Child Table That Are Not In Another And Parent Has No Other Children
I’m trying to write a query to select all orphan records that are in a child table, but only when orphaned records are the only items in the table. I have two separate databases from separate systems,…
SQL to return 1 for each row with column range in 2017 or 2018 or 2019
I have a query that looks like this: SELECT DISTINCT p.person_ID ,p.Last_Name ,ISNULL(p.Middle_Initial, ”) AS Middle ,p.First_Name ,sh.Status_from_date ,sh….
Dynamic Pivot of Email Addresses
I have tried to research this, and I am unable to find something quite like it. I have a table that may have entries added many times over as well as deleted. I have no idea how many columns I will …
Unexpected NULLs in outer join
I have 3 tables I’m trying to join. Let’s call them TableA, TableB, and TableC: DECLARE @TableA TABLE ( Key1 int, PRIMARY KEY ( Key1 ) ) DECLARE @TableB TABLE ( Key1 int, …