Solved

Appending text to a variable in SSIS

Posted on 2007-11-30
5
1,905 Views
Last Modified: 2013-11-30
I have an "Execute SQL Task" in an dtsx package that sends an email using the following code...
EXEC msdb.dbo.sp_send_dbmail
      @profile_name = 'SQL Mail',
       @recipients = 'Test@test.com',
      @copy_recipients = 'test1@test.com',
      @body = ?,
      @subject = 'Some title' ;
This works fine, however I want to add more text to the body (as ? only supplies a single counter value)
I have tried a number of different versions of the code... the following is what I am trying to do...
      @body = 'The number is: ' ?,
However this is not working... neither is @body = 'The number is: ' + ?,
If anyone out there knows how to get around this it would be much appreciated (the input variable ? is of type varchar)
Thanks in advance
0
Comment
Question by:MTSDL
[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
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
digital_thoughts earned 500 total points
ID: 20381974
What is the error you get when you try:

@body = 'The number is: ' + ?

Just taking a guess it has to do with trying to add a string and a counter value together, you might just need to CAST the counter value to a string first:

@body = 'The number is: ' + CAST(? AS VARCHAR(10))
0
 

Author Comment

by:MTSDL
ID: 20382402
I have tried the above example and there was an error for that as well.

The following is the error that I get...
Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
0
 
LVL 8

Expert Comment

by:digital_thoughts
ID: 20382589
Hmm, ok not sure what is going on... how about giving this a try:

@body = ?,
@body = 'The number is: ' + @body,
0
 

Author Comment

by:MTSDL
ID: 20394472
I have tried the above code and that did not work either...

What I have done is the following... and it works a treat

SELECT 'The number is: ' + cast(count(*) as varchar) AS CountText FROM Table

I pass CountText to the next "Execute SQL Task" and it works fine
0
 
LVL 8

Assisted Solution

by:digital_thoughts
digital_thoughts earned 500 total points
ID: 20395568
Yes, that would work just fine, any time you need to add a non-string (varchar) value to a varchar you will need to cast or convert it. I should have asked what exactly ? was as it wasn't directly clear in your originally post. Regardless, glad you got it to work.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

734 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