Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Passing a concat string to a SP parameter

Author  Topic 

malachi151
Posting Yak Master

152 Posts

Posted - 2011-04-19 : 12:42:51
I have a stored procedure that takes a varchar input parameter, and I need to pass a concatinated string to that parameter, but I get an error when trying to do so. Is there any way to do this other than creating yet one more variable and assigned the concatinated value to that variable and then passing the variable?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-19 : 12:52:24
Can you post the code of the procedure, the statement you're calling it with, and the error message you're getting?
Go to Top of Page

malachi151
Posting Yak Master

152 Posts

Posted - 2011-04-19 : 12:58:13
It's a pretty basic issue.

EXEC sp_Log_Event @database, 9, 'Test'+@LogMessage, @User;

Error:
Incorrect syntax near '+'.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-19 : 13:05:50
SET @LogMessage='Test'+@LogMessage
EXEC sp_Log_Event @database, 9, @LogMessage, @User;
Go to Top of Page

malachi151
Posting Yak Master

152 Posts

Posted - 2011-04-19 : 13:31:42
quote:
Originally posted by robvolk

SET @LogMessage='Test'+@LogMessage
EXEC sp_Log_Event @database, 9, @LogMessage, @User;



Yeah, I know, as I said in the OP, I was hoping there was a way to do this without having to create yet one more variable, because, in this case, I need @LogMessage to remain unchanged and not have the prefix permanently appended becuase it gets used somewhere else in a different way.

It's not a huge issue, I was just hoping there was some way to concat in-line in the call to the sp without having to use another variable, but its easy enough to deal with.
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2011-04-19 : 14:09:07
In Re: "I was hoping there was a way to do this without having to create yet one more variable"

There isn't.

=======================================
Elitism is the slur directed at merit by mediocrity. -Sydney J. Harris, journalist (1917-1986)
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-19 : 14:15:21
Well, maybe:

SET @LogMessage='Test'+@LogMessage
EXEC sp_Log_Event @database, 9, @LogMessage, @User;
SET @LogMessage=STUFF(@LogMessage,1,4,'')
Go to Top of Page
   

- Advertisement -