Return a value from a Function

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2007
Posts: 176
Reputation: Kusno is an unknown quantity at this point 
Solved Threads: 13
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster

Return a value from a Function

 
0
  #1
Jul 23rd, 2009
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 :

  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 :

  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
NEVER NEVER NEVER GIVE UP
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 2
Reputation: shijobaby has a little shameless behaviour in the past 
Solved Threads: 0
shijobaby shijobaby is offline Offline
Newbie Poster

Re: Return a value from a Function

 
0
  #2
Aug 21st, 2009
Hi

Actually this in the group of small errors consuming time

Just have aook on my blog

http://sqlerrormessages.blogspot.com...t-assigns.html


Happy Programming
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC