Solved

Appending text to a variable in SSIS

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

914 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

17 Experts available now in Live!

Get 1:1 Help Now