﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Integration Services / Data Warehousing  / Whats wrong with this concatenation? / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 08:21:56 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Whats wrong with this concatenation?</title><link>http://www.sqlservercentral.com/Forums/Topic1374114-364-1.aspx</link><description>I would dump the expression and use Execute SQL Task as it is easier to read and maintain.Here is what I would do, you might need to tweak as I took 10 minutes just to put this together:[code="other"]/* comment out declares and set in sql task   set-up ado.net connection   pass in variables that are declared here   Set-up result set to single row   For result set, set result name to 0, use user variable FileLoadNumber as variable name   DECLARE @BatchID INTDECLARE @FileLoadNumber intDECLARE @BatchDateISO datetimeSET @BatchID = 11SET @BatchDateISO = GETDATE()SET @FileLoadNumber = '9'*/Select CAST(@BatchID AS VARCHAR(20))     + 'FHAS400'      + CASE WHEN LEN(@FileLoadNumber) = 0 then '0' + convert(char(8),@BatchDateISO,112)         ELSE CAST(@FileLoadNumber AS VARCHAR(10)) + convert(char(8),@BatchDateISO,112)  end[/code]</description><pubDate>Fri, 19 Oct 2012 12:37:41 GMT</pubDate><dc:creator>churlbut</dc:creator></item><item><title>RE: Whats wrong with this concatenation?</title><link>http://www.sqlservercentral.com/Forums/Topic1374114-364-1.aspx</link><description>Like this?"Select "+(DT_STR, 20, 1252)@[User::BatchID] + " as BatchID, '" +@[User::BatchDateISO] + "' as BatchDateISO, 'FH' as RecordType, 'AS400' as SourceSystem, " +RIGHT("00" + (DT_STR, 10, 1252)@[User::BatchID],2) + @[User::BatchDateISO] + " as FileLoadNumber"Your expression references FileLoadNumber variable, which you did not say what its value is or where it fits in, But why are you doing that crazy case?Simple RIGHT("00" + (DT_STR, 10, 1252)@[User::BatchID],2) will Create a string 009, and then take the Right 2 characters, ie 09. if the batch id is 19 then it will create a string 0019 and then take the Right 2 chars getting 19.</description><pubDate>Thu, 18 Oct 2012 13:14:14 GMT</pubDate><dc:creator>Ray M</dc:creator></item><item><title>RE: Whats wrong with this concatenation?</title><link>http://www.sqlservercentral.com/Forums/Topic1374114-364-1.aspx</link><description>Hi Learner,A suggestion and a question.  The suggestion.  It's very helpful if you do not cross-post your questions.  That keeps the responses in one place.  Folks will find the question wherever you put it.The question. I'm confused about what the issue is.  Is the expression not giving the expected output or is the output not giving the expected query results?</description><pubDate>Thu, 18 Oct 2012 12:21:50 GMT</pubDate><dc:creator>kl25</dc:creator></item><item><title>Whats wrong with this concatenation?</title><link>http://www.sqlservercentral.com/Forums/Topic1374114-364-1.aspx</link><description>I have this SSIS expression and it is evaluated as below with the default values replacing the SSIS variables. This is the raw expression:"Select "+(DT_STR, 20, 1252)@[User::BatchID]+ " as BatchID, '" +@[User::BatchDateISO]+ "' as BatchDateISO, 'FH' as RecordType, 'AS400' as SourceSystem, CASE WHEN LEN("+(DT_STR, 10, 1252)@[User::FileLoadNumber]+") = CAST(1 as VARCHAR) THEN '0'+'"+ (DT_STR, 10, 1252) @[User::FileLoadNumber]+"'+'"+@[User::BatchDateISO]+"' ELSE '"+ (DT_STR, 10, 1252) @[User::FileLoadNumber]+"'+'"+@[User::BatchDateISO]+"' END as FileLoadNumber" It is evaluated as:Select 9 as BatchID, '20121017' as BatchDateISO, 'FH' as RecordType, 'AS400' as SourceSystem, CASE WHEN LEN(9) = CAST(1 as VARCHAR) THEN '0'+'9'+'20121017' ELSE '9'+'20121017' END as FileLoadNumberThis is returning the result without appending 0, which means always the ELSE part in CASE is chosen for FileLoadNumber column value.If the BatchID value is of single digit it has to concatenate with BatchDateISO by appending 0 in front of BatchIDIf BatchID is 9, then the result should be 0920121017 for FileLoadNumber columnIf it is 19, then the result should be 1920121017 for FileLoadNumber columnThanks a lot!</description><pubDate>Wed, 17 Oct 2012 20:09:59 GMT</pubDate><dc:creator>Learner093</dc:creator></item></channel></rss>