tsql - Inserting concatenated values in T-SQL -


ok, trying achieve:

my script below supposed gather values across 3 tables , insert them in table b in sequence.

there 2 columns being affected in table b indxlong , ddline.

in ddline row attempting concatenate values different fields , store them one.

my code below. please share insights:

declare     @nrowcount int,      @indxlong int,     @hdrlocal char(255),        @cr char(255),        @bldchkdt datetime,     @bldchtime datetime,        @hdrline int,        @1strowline int,        @2ndrowline int,        @3rdrowline int,        @bwp char(255),        @compacc char(11),        @bankcode char(11),      @branchno char(11),        @paydate datetime,        @reference char(11),      @totaamt numeric(19,5)     @coname char(11),        @beneficiaryacc char(11),        @benbankbranchcode char(11),        @salary numeric (19,5),        @beneficiaryname char(23),        @transref char(23),        @outer_c int   select @compacc =ddcoiden,        @bankcode =ddimorig,        @branchno =ddimdest,        @reference =dddesc10,        @coname =ddimornm table  declare ach scroll cursor   select t762.ddindnam,         t762.ddtranum,         t762.ddactnum,         t762.ddamtdlr,         t756.paydate         stats.dbo.table c t762         left outer join stats.dbo.table d t756 on (                 t762.indxlong = t756.indxlong                 , t756.inclpymt = 1                 )         (t756.inclpymt = 1)             , (t762.ddamtdlr <> 0) read only;  open ach; set nocount on; fetch ach @beneficiaryname,@benbankbranchcode,@beneficiaryacc,@salary,@paydate  while @@fetch_status = 0 begin          select @totaamt =sum(@salary)          set @hdrline =1          set @1strowline =2          set @2ndrowline =3          set @3rdrowline =9          select @hdrlocal = ddline table e indxlong =1          select @cr = ddline table e indxlong =2          select @bwp = ddline table e indxlong =3  begin     insert table b (indxlong,ddline)     values (1,@hdrlocal + ',' + @cr + ',' )     select @@identity end begin insert table b (indxlong,ddline)     values (2,@compacc + @branchno +','+ @bwp+ ',' + @paydate +',' + @reference + ','+@totaamt + ','+ @transref)     select @@identity end  begin insert table b (indxlong,ddline) values (3,@beneficiaryacc + ',' + @benbankbranchcode +','+ @beneficiaryacc+ ',' + @salary +',' + @reference + ','+@totaamt + ','+ @transref)     select @@identity end fetch ach @beneficiaryname,@benbankbranchcode,@beneficiaryacc,@salary,@paydate end  close ach deallocate ach set nocount off; 

this error:

msg 8152, level 16, state 14, line 69
string or binary data truncated.
statement has been terminated.
msg 241, level 16, state 1, line 74
conversion failed when converting date and/or time character string.

this result aiming for:

 indxlong    ddline                                                                                                                                                                                                                                                         ----------- ----------------------------------------------------------------------- 1           101001       029       1403200610a094101 amen  bank          love     2           123456 111               34567   ppdsalarypayt140131140117   11234567  3           63206623    0101962706200    0000062709000319614      adams eve           

cast dates varchars/nvarchars if going concatenate them. examples, @paydate should casted this: cast(paydate varchar(20)). or if need date in specific format, use convert.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -