Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Concat parameter in a message Expand / Collapse
Author
Message
Posted Monday, June 2, 2014 12:28 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, June 11, 2014 7:45 PM
Points: 14, Visits: 36
Hi,

I have a procedure (a) where i call another procedure (b) passing @message as a parameter to procedure B.
Ex:
Create procedure a
as
Begin
declare @prevyear
exec b @message = 'avvasdva' + cast(@prevyear as varchar)
End

When i execute above procedure, i get error at + sign i.e. @message parameter. how can i concatenate string with another parameter when passing parameters
Post #1576709
Posted Monday, June 2, 2014 1:05 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 10:32 AM
Points: 1,248, Visits: 3,628
vasuarjula (6/2/2014)
Hi,

I have a procedure (a) where i call another procedure (b) passing @message as a parameter to procedure B.
Ex:
Create procedure a
as
Begin
declare @prevyear
exec b @message = 'avvasdva' + cast(@prevyear as varchar)
End

When i execute above procedure, i get error at + sign i.e. @message parameter. how can i concatenate string with another parameter when passing parameters


Check out this page and if you have any further questions, feel free!
Post #1576737
Posted Monday, June 2, 2014 1:57 PM This worked for the OP Answer marked as solution


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:51 AM
Points: 13,252, Visits: 10,135
Parameters cannot be expressions.

http://stackoverflow.com/questions/12009832/how-to-concatenate-string-when-setting-a-parameter-in-transact-sql

Specify Parameters




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1576755
Posted Monday, June 2, 2014 3:44 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 9:45 AM
Points: 36,736, Visits: 31,188


That's step one, for sure. Step 2 is that the variable is assigned no value and will always return a NULL for the result of the concatentation. Step 3 is that the variable if the variable is provided from sources external to the proc, a check needs to be done for SQL Injection.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1576788
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse