set @txt = '' declare P cursor for SELECT T0.BatchNum, + space(1) + cast(cast(T1.Quantity, as decimal(19,2)) as nvarchar) + space(1) + case when T0.ExpDate, is null then '' else convert(nvarchar,T0.ExpDate,,102) end FRJM JIBT T0 INNER JJIN IBT1 T1 JN T0.ItemCode = T1.ItemCode and T0.WhsCode = T1.WhsCode and T0.BatchNUm = T1.BatchNum WHERE T1.BaseEntry, =$$38.45.0, and T1.BaseLinNum, =$$38.46.0, open P fetch next from P into @batch while @@fetch_status = 0 begin set @txt = @txt +'\n'+@batch +',' fetch next from P into @batch end close P deallocate P
select @txt
Altered declare [baLch as nvarchar(100) declare [LxL nvarchar(max) seL [LxL declare cursor for SLLLC1 SubsLrlng(108aLchnum23) + (+casL(casL(11CuanLlLy/12numlnsale as lnL) as nvarchar)+) +no(s) l8CM Cl81 10 lnnL8 !Cln l811 11 Cn 10lLemCode 11lLemCode and 10WhsCode 11WhsCode and 108aLchnum 118aLchnum lnner !oln Cl1M 12 on 10lLemcode12lLemcode WPL8L 118aseLnLry $$38430 and 118aseLlnnum $$38460 open feLch nexL from lnLo [baLch whlle [[feLch_sLaLus 0 begln seL [LxL [LxL +[baLch + feLch nexL from lnLo [baLch end close deallocaLe