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 6947299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:40:34+00:00 2026-05-27T13:40:34+00:00

I have the function which gets ID and returns date from table if it

  • 0

I have the function which gets ID and returns date from table if it exists or returns current date if isn’t:

CREATE FUNCTION [dbo].[CLOSEDATE] (@ID int)
RETURNS datetime
AS
  BEGIN
     DECLARE @closed int;
     DECLARE @result datetime;

     SELECT @result = created_on from dbo.statuses_history
            WHERE journalized_id = @ID and new_status = 'Закрыто';

     IF @result IS NULL    
        SELECT @result = GETDATE()     

     RETURN (DATEADD(dd, 0, DATEDIFF(dd, 0, @result)))
  END;

The next queries return correct date from table:

select dbo.closedate(4170)
select dbo.closedate(id) from issues where id = 4170

And the next code update the record correctly (values from table):

DECLARE @d AS datetime
select @d = dbo.closedate(4170)
UPDATE issues SET created_on = @d  WHERE issues.id = 4170

But I get current date in the field if I update the record:

UPDATE issues
SET created_on = dbo.CloseDate(id)
WHERE issues.id = 4170

It looks like the ID parameter doesn’t pass to the function.

  • 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-27T13:40:35+00:00Added an answer on May 27, 2026 at 1:40 pm

    Your tests (that I missed on the first reading, sorry) are enough to make me very confused. It seems that your test results should not be possible.

    My only suggestion would be to recode the function and see what happens…

    CREATE FUNCTION [dbo].[CLOSEDATE] (@ID int)
    RETURNS TABLE
    AS
    RETURN
      SELECT
        (DATEADD(dd, 0, DATEDIFF(dd, 0, ISNULL(MAX(created_on), GetDate())))) AS close_date
      FROM
        dbo.statuses_history
      WHERE
        journalized_id = @ID
        AND new_status = 'Закрыто'
    

    And then…

    UPDATE
      issues
    SET
      created_on = fn.close_date
    FROM
      issues
    CROSS APPLY
      dbo.CLOSEDATE(id) AS fn
    WHERE
      issues.id = 4170
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function which gets a key from the user and generates a
i have an ajax function which gets called and returns json data. this function
Have a function in tableview.m which gets me the start date and I add
So I have a function which returns a pdf stream. The calling procedure gets
I have a function which searches an STL container then returns the iterator when
i have a function which retrieves values from a webservice , then loops through
I have a function which returns a one-sided intersection of values between two input
I have a function which performs a foreach loop on an array from a
I have a function which calculates distance from database records. This function is called
Alright so I have a php script which gets results from a DB, and

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.