views:

75

answers:

4

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 languages, but I didn't know if SQL was capable of this at all.

+1  A: 

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

Scott Anderson
+3  A: 

How about:

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

(MSSQL syntax - similar)

ck
bjorsig
The + operator in Access/Jet/ACE is the null-propagating concatenation operator for string values (though it will sum numeric values).
David-W-Fenton
A: 

One way to do this:

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

Randy Minder
A: 

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

Jeff O
You're writing SQL that can't run except as a passthrough in Access. Frankly, it makes no sense to me at all to use any kind of SQL or UDF for this function, as it's so easy to do inline within Access/Jet/ACE SQL.
David-W-Fenton
@David W Fenton - The question asked for a stored proc. A UDF can be used to centralize the logic to be used in multiple stored procedures, views or SQL statements. We've yet to determine if the question is looking for a pure Access answer or a SQL Server.
Jeff O
Access doesn't have stored procedures (except in the very limited sense of a parameter-based QueryDef). Access doesn't allow procedural code. There is nothing at all in the question that suggests SQL Server is involved (stored procedures are not exclusive to SQL Server, BTW).
David-W-Fenton