Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 909397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:52:15+00:00 2026-05-15T16:52:15+00:00

I am trying to call an IF statement on my trigger so it won’t

  • 0

I am trying to call an IF statement on my trigger so it won’t archive expired files. (I only want to keep files that have been deleted but have not been expired)

My error is The multi-part identifier “d.ExpiryDate” could not be bound.

My Code:

    ALTER TRIGGER [dbo].[ArchiveDB] 
   ON  [dbo].[TBL_Content] 
   AFTER DELETE
AS 

BEGIN

declare @ContentID int

set @ContentID = (select ContentID from deleted)

IF (d.ExpiryDate > getDate() )
    begin
        insert into ArchiveBackup.dbo.TBL_Deleted_Content
        (ContentID, StartDate, ExpiryDate, Title... etc)
        select 
        d.ContentID,d.StartDate,d.ExpiryDate,d.Title... etc 
        from deleted as d
    end

END

Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:52:16+00:00Added an answer on May 15, 2026 at 4:52 pm

    You’d have to tell SQL Server where to find the ExpiryDate, like:

    if ((select ExpiryDate from deleted) > getdate())
    

    Be aware that a trigger can be called for cases when multiple rows where deleted. It might be better to replace the entire if contruct with a query:

    insert into ArchiveBackup.dbo.TBL_Deleted_Content
    (ContentID, StartDate, ExpiryDate, Title... etc)
    select 
    d.ContentID,d.StartDate,d.ExpiryDate,d.Title... etc 
    from deleted as d
    where ExpiryDate > getdate()
    

    Or even better, write a stored procedure that deletes rows instead of deleting them directly from the table. Stored procedures are way easier to understand and maintain than triggers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to call the SQL statement below but get the following error: System.Data.SqlClient.SqlException:
I am trying to call a shell script that sets a bunch of environment
I'm trying to use CROSS APPLY in SQL, but only want to use the
I have been trying to execute the following UNIX shell script which is not
When trying to call Close or Dispose on an SqlDataReader i get a timeout
I'm trying to call an Antlr task in my Ant build.xml as follows: <path
I'm trying to call a function after I load some XML into Actionscript, and
I am trying to call a webservice using ssl. How do i get the
I'm trying to call a web service from Excel 2003 module. The way i've
I'm trying to call a php webservice using WCF. I googled some public php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.