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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:13:42+00:00 2026-05-10T17:13:42+00:00

I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)

  • 0

I have the following function:

CREATE FUNCTION fGetTransactionStatusLog (     @TransactionID  int ) RETURNS varchar(8000) AS   BEGIN   declare StatusChanges cursor for     select  NewStatusID, FirstName + ' ' + LastName AS UserName, Stamp, CAST(Notes AS varchar(8000)) AS Notes       from TransactionStatusChanges tsc         left join Users us ON tsc.UserID = us.UserID       where TransactionID = @TransactionID ORDER BY StatusNum  declare @output varchar(8000)  declare @NewStatusID char(2) declare @UserName varchar(255) declare @Stamp datetime declare @Notes varchar(8000)  set @output = ''  OPEN StatusChanges   FETCH NEXT FROM StatusChanges INTO @NewStatusID, @UserName, @Stamp, @Notes   WHILE @@FETCH_STATUS = 0   BEGIN      set @output = @output + RTRIM(CAST(@Stamp AS varchar(30))) + ': ' + @NewStatusID + ' by ' + @UserName +  CHAR(13) + CHAR(10)      IF @Notes IS NOT NULL     BEGIN         set @output = @output + '---' + @Notes +  CHAR(13) + CHAR(10)     END      FETCH NEXT FROM StatusChanges INTO @NewStatusID, @UserName, @Stamp, @Notes   END CLOSE StatusChanges DEALLOCATE StatusChanges  RETURN @output  END 

Now, that function returns exactly what I want for the Transactions that don’t have any Notes in any records… For transaction that have at least one record in TransactionStatusChanges with a non-NULL Notes field, I get NULL.

I don’t quite get it, since I AM checking that @Notes is not NULL before concatting it.

Any ideas?

NOTE: I’m using varchar(8000) because I can’t use text inside Functions.

  • 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. 2026-05-10T17:13:43+00:00Added an answer on May 10, 2026 at 5:13 pm

    One of these is NULL

       set @output = @output + RTRIM(CAST(@Stamp AS varchar(30))) + ': ' + @NewStatusID + ' by ' + @UserName +  CHAR(13) + CHAR(10) 

    Also, you can make your code simpler by using ISNULL or COALESCE to handle columns which contain NULLs

    CREATE FUNCTION fGetTransactionStatusLog (     @TransactionID  int ) RETURNS varchar(8000) AS   BEGIN   declare @output AS varchar(8000)  select @output = ISNULL(@output, '')         + ISNULL(RTRIM(CAST(Stamp AS varchar(30))), '<NULL>')         + ISNULL(NewStatusID, '<NULL>') + ' by '         + ISNULL(FirstName + ' ' + LastName, '<NULL>') + CHAR(13) + CHAR(10)         + ISNULL('---' + Notes +  CHAR(13) + CHAR(10), '') from TransactionStatusChanges tsc left join Users us ON tsc.UserID = us.UserID where TransactionID = @TransactionID ORDER BY StatusNum  RETURN @output  END 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer foreach (Process p in Process.GetProcesses()) { if (String.Equals(p.ProcessName, name)) {… May 11, 2026 at 11:58 am
  • added an answer After lots of trial & error, here's what I ended… May 11, 2026 at 11:58 am
  • added an answer SUBSTRING_INDEX: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring-index SELECT SUBSTRING_INDEX(`name`, ' ', 1); May 11, 2026 at 11:58 am

Related Questions

I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I have the following function that is pulling data from a database. The ajax
So: I have the following function, adapted from a formula found online, which takes
Let's say I have the following function: sumAll :: [(Int,Int)] -> Int sumAll xs
I have the following Oracle function: function get_job_no return number is V_job_no number; begin
Say I have the following code: function One() {} One.prototype.x = undefined; function Two()
I have the following intentionally trivial function: void ReplaceSome(ref string text) { StringBuilder sb
I have the following serialization method: Private Function SerializeData(ByVal data As cData) As String
I have the following situation: I have a certain function that runs a loop
I have the following JavaScript code: Link In which the function makewindows does not

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.