Link to home
Start Free TrialLog in
Avatar of fskilnik
fskilnikFlag for Brazil

asked on

exec with string + variable

Hi there,

This code (below) does not work, although the sproc is perfect... I am SURE the problem is in the bold part. How should I correct it?

(It must insert a certain "Package Number 14" to the student with the email given)

Thanks!

(I know a variable would NOT be needed here, but with this correction I will put a WHILE thing to happen afterwards, therefore please help as requested.)

--------------------------------------------

USE [dbName]
GO

DECLARE      
@return_value int,
@PackNumber int

SET @PackNumber = 14

EXEC      @return_value = [dbo].[insMaterial_sproc]
            @EmailLogin = N'emailgiven_thisOk',
            @MaterialName = 'Package Number'+@PackNumber

SELECT      'Return Value' = @return_value
GO
Avatar of BAKADY
BAKADY
Flag of Germany image

try this, maybe help... if not please post your error message too...
EXEC      @return_value = [dbo].[insMaterial_sproc]
            @EmailLogin = N'emailgiven_thisOk',
            @MaterialName = 'Package Number ' + cast(@PackNumber as varchar(max))

Open in new window

regards
ASKER CERTIFIED SOLUTION
Avatar of Nem Schlecht
Nem Schlecht
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also, this line doesn't make any sense:
SELECT      'Return Value' = @return_value

Open in new window


You probably want this instead:

SELECT      'Return Value: ' + CAST(@return_value AS VARCHAR(40))

Open in new window

@MaterialName = 'Package Number'+str(@PackNumber)
Avatar of fskilnik

ASKER

Thanks for you all. (Sorry for the delay, too busy...)

@BAKADY: error message - "Incorrect syntax near '+'."

@nemws1: PERFECT (and great explanation, thank you)

(On the SELECT matter: the original line was not changed, and it worked anyway, but thanks for this additional suggestion)

@vivekkumarSharma: error message - "Incorrect syntax near '+'."