Insert trigger checking for specific column I have got an insert trigger on a table. The table got a field named 'source'.
The source field could be populated with values b or left empty as in null.
i want the trigger only to fire if the source field is not populated with 'b'.
The below trigger codes deosnt give me error, but never runs.
if i remove the if condition it runs, but i need to check for value of 'b' before it should run.

Create TRIGGER TriggerName
ON tableName
FOR INSERT
AS 
BEGIN

DECLARE @source nvarchar(50)

SELECT                  @source = (select source  from inserted)

             if not (@source = 'b') 
                begin

                INSERT INTO ATable
                (field1,field2,field3)  
                SELECT i.field1,i.field2,i.field3
                FROM inserted i 

                    end
end
I've tried to re-create what you're doing on my local instance, here's what I've got:-

I created two tables, one for the data to be inserted to and one for the trigger to insert to:-

CREATE TABLE dbo.[TriggerTest]
(Source         CHAR(1),
 TestColSource  CHAR(1));
GO

CREATE TABLE dbo.[InsertTest]
(TestColDest CHAR(1));
GO


I then created this trigger (as @Aaron Bertrand says, removing the variable assignment):-

CREATE TRIGGER TRG_TriggerTest
ON dbo.[TriggerTest]
FOR INSERT
AS 
BEGIN
    INSERT INTO dbo.[InsertTest]
        (TestColDest)  
    SELECT i.TestColSource
    FROM inserted i
    WHERE i.SOURCE &lt;&gt; 'b'
END


I then inserted some data into the initial table:-

INSERT INTO dbo.[TriggerTest]
SELECT 'a', '1'
UNION
SELECT 'b', '2'
UNION 
SELECT 'c', '3'


The trigger should only insert the 1 &amp; 3 values from the above statement, but this can be checked by:-

SELECT TestColDest FROM dbo.[InsertTest]


Hopefully that should give you a basis for your trigger. I'm sure the guys on here will correct me if I've got something wrong.