Solved

exec with string + variable

Posted on 2013-06-12
5
251 Views
Last Modified: 2013-06-13
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
0
Comment
Question by:fskilnik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:BAKADY
ID: 39242861
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
0
 
LVL 23

Accepted Solution

by:
nemws1 earned 500 total points
ID: 39242875
You can't have any "function" as a part of an EXEC call.  You also can't concatenate a string and an INT without a CAST.  Combine the string beforehand:

USE [dbName]
GO

DECLARE      
@return_value int,
@PackNumber int,
@PackNumString VARCHAR(100)


SET @PackNumber = 14;
SET @PackNumString = 'Package Number' + CAST(@PackNumber AS VARCHAR(40));

EXEC      @return_value = [dbo].[insMaterial_sproc]
            @EmailLogin = N'emailgiven_thisOk',
            @MaterialName = @PackNumString

SELECT      'Return Value' = @return_value
GO 

Open in new window

0
 
LVL 23

Expert Comment

by:nemws1
ID: 39242884
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

0
 
LVL 2

Expert Comment

by:vivekkumarSharma
ID: 39243615
@MaterialName = 'Package Number'+str(@PackNumber)
0
 

Author Comment

by:fskilnik
ID: 39246293
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 '+'."
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question