开发者

Can an SQL stored procedure simply return its inputs, concatenated?

To fit an edge case, I'd like to create a stored procedure (Access SQL!) which simply returns the concatenation of three inputs. So

MyProcedure('AAA','BBB','CCC')

returning

'AAA,BBB,CCC'

Obviously this is elementary in most programming la开发者_运维问答nguages, but I didn't know if SQL was capable of this at all.


How about:

select @param1 + ',' + @param2 + ',' + @param3

(MSSQL syntax - similar)


You can do this with simple string concatenation. Check out this site for more information on how to do it with access (hint, use the & operator):

http://www.techonthenet.com/access/functions/string/concat.php


One way to do this:

@Param1 + ',' + @Param2 + ',' + @Param3


A stored procedure would not be as flexible as a user defined function

Create Function dbo.udf_Concat (
 @String1 varchar(100) 
  , @String2 varchar(100) 
  , @String3 varchar(100) 
)
Returns varchar(300)
AS
Begin
Return (
 Select @String1 + @String2 + @String3
)
End

Then to use it in a query: Select dbo.udf_Concat('this', ' that', ' the other') as The_Three_Strings

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜