Solved

Appending text to a variable in SSIS

Posted on 2007-11-30
5
1,896 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now