943,688 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Marked Solved
  • Views: 565
  • MS SQL RSS
Jul 23rd, 2009
0

Return a value from a Function

Expand Post »
Dear all,
Sorry, if this Thread is wrong room .

I want to return a field value from a table, so I created a function like this :

MS SQL Syntax (Toggle Plain Text)
  1. CREATE FUNCTION dbo.CheckStatusTrx(@TransNo Varchar(20))
  2. RETURNS varchar(20)
  3. AS
  4. BEGIN
  5. DECLARE @Flag Numeric(1)
  6. SELECT @Flag = Flag, CreatedBy, ApprovedBy FROM TrxTD WHERE TransNo = @TransNo
  7. IF @Flag = 2 RETURN 'REJECTED'
  8. END

but, I got this error :

MS SQL Syntax (Toggle Plain Text)
  1. Msg 141, Level 15, State 1, Procedure CheckStatusTrx, Line 6
  2. A SELECT statement that assigns a value TO a variable must NOT be combined WITH data-retrieval operations.

Help me, what should I do?

Thanks
Similar Threads
Reputation Points: 11
Solved Threads: 17
Junior Poster
Kusno is offline Offline
191 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Big problem with table
Next Thread in MS SQL Forum Timeline: Import XML to SQL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC