I'm having a hard time to return a string value. I usually do this by passing an int, which works just fine. Now, I need to pass a string but couldn't.

Is this possible? Or int is only type that SQL can return?

Recommended Answers

All 3 Replies

if you must return some value ,go for a function .

function? How to do it?

Here's a simple example of how to use output variables in stored procedures:

CREATE PROC dbo.ReturnString 
    @string VARCHAR(500)
   ,@outputString VARCHAR(500) OUTPUT
AS
SET @outputString = @string
GO

Then to call the stored procedure, you'll want to declare a variable and assign the value like so:

DECLARE @output VARCHAR(500)
EXEC dbo.ReturnString 'output string',@outputString = @output OUTPUT
PRINT 'Here''s your output string: ' + @output
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.