Select stock.WStockid,1.0 ratio , substring(SPATH {If SQL Server},{else}from{endif} 6 {If SQL Server},{else}for{endif} 200) Path , trim(sgroup{concat}'-'{concat} l.IMP_EXTID)  {concat} '.jpg'  dest ,0 maxwidth,0 MAXHEIGTH,0 quality  FROM
MULTIMEDIA join stock on  WREFID = stock.WStockid
join imp_link l on l.wstockid = stock.wstockid and l.IMP_SOURCEID = <@IMP_SOURCEID@>
 where STYPE = 'STOCK' and  (SPATH like 'link:%' or SPATH like 'file:%') 
and WREFID = <@WSTOCKID@> and SGroup = 'products_image' 
union 
 Select stock.WStockid,1.0 ratio ,  substring(SPATH {If SQL Server},{else}from{endif} 6 {If SQL Server},{else}for{endif} 200) Path , 'products_image_small'   {concat}'-'{concat} trim(l.IMP_EXTID)  {concat} '.jpg'  dest , 150 ,150,70 FROM
MULTIMEDIA join stock on  WREFID = stock.WStockid
join imp_link l on l.wstockid = stock.wstockid and l.IMP_SOURCEID = <@IMP_SOURCEID@>
where STYPE = 'STOCK' and  (SPATH like 'link:%' or SPATH like 'file:%') 
and WREFID = <@WSTOCKID@> and SGroup  = 'products_image'

union
Select stock.WStockid,1.0 ratio , substring(SPATH {If SQL Server},{else}from{endif} 6 {If SQL Server},{else}for{endif} 200) Path , trim(sgroup{concat}'-'{concat} l.IMP_EXTID)  {concat} '.jpg'  dest, 0 maxwidth,0 maxheight,0 quality   FROM
MULTIMEDIA join stock on wrefid = wstockid 
join imp_link l on l.wstockid = stock.wstockid and l.IMP_SOURCEID = <@IMP_SOURCEID@>
where WREFID = <@WSTOCKID@> and STYPE = 'STOCK' and (SPATH like 'link:%' or SPATH like 'file:%') 
and (  SGROUP = 'products_subimage1' )

union
Select stock.WStockid,1.0 ratio , substring(SPATH {If SQL Server},{else}from{endif} 6 {If SQL Server},{else}for{endif} 200) Path , trim(sgroup{concat}'-'{concat} l.IMP_EXTID)  {concat} '.jpg'  dest, 0 maxwidth,0 maxheight,0 quality  FROM
MULTIMEDIA join stock on wrefid = wstockid 
join imp_link l on l.wstockid = stock.wstockid and l.IMP_SOURCEID = <@IMP_SOURCEID@>
where WREFID = <@WSTOCKID@> and STYPE = 'STOCK' and (SPATH like 'link:%' or SPATH like 'file:%') 
and ( SGROUP = 'products_subimage2')

union
Select stock.WStockid,1.0 ratio , substring(SPATH {If SQL Server},{else}from{endif} 6 {If SQL Server},{else}for{endif} 200) Path , trim(sgroup{concat}'-'{concat} l.IMP_EXTID)  {concat} '.jpg'  dest, 0 maxwidth,0 maxheight,0 quality  FROM
MULTIMEDIA join stock on wrefid = wstockid
join imp_link l on l.wstockid = stock.wstockid and l.IMP_SOURCEID = <@IMP_SOURCEID@>
 where WREFID = <@WSTOCKID@> and STYPE = 'STOCK' and (SPATH like 'link:%' or SPATH like 'file:%') 
and (   SGROUP = 'products_subimage3' )

union
Select stock.WStockid,1.0 ratio , substring(SPATH {If SQL Server},{else}from{endif} 6 {If SQL Server},{else}for{endif} 200) Path , sorgfilename dest, 0 maxwidth,0 maxheight,0 quality  FROM
MULTIMEDIA join stock on wrefid = wstockid 
join imp_link l on l.wstockid = stock.wstockid and l.IMP_SOURCEID = <@IMP_SOURCEID@>
where WREFID = <@WSTOCKID@> and STYPE = 'STOCK' and (SPATH like 'link:%' or SPATH like 'file:%') 
and (   SGROUP = 'products_subimage4' )

union
Select stock.WStockid,1.0 ratio , substring(SPATH {If SQL Server},{else}from{endif} 6 {If SQL Server},{else}for{endif} 200) Path , trim(sgroup{concat}'-'{concat} l.IMP_EXTID)  {concat} '.jpg'  dest,  0 maxwidth,0 maxheight,0 quality  FROM
MULTIMEDIA join stock on wrefid = wstockid 
join imp_link l on l.wstockid = stock.wstockid and l.IMP_SOURCEID = <@IMP_SOURCEID@>
where WREFID = <@WSTOCKID@> and STYPE = 'STOCK' and (SPATH like 'link:%' or SPATH like 'file:%') 
and (   SGROUP = 'products_subimage5' )
union
Select stock.WStockid,1.0 ratio , substring(SPATH {If SQL Server},{else}from{endif} 6 {If SQL Server},{else}for{endif} 200) Path , trim(sgroup{concat}'-'{concat} l.IMP_EXTID)  {concat} '.jpg'  dest,  0 maxwidth,0 maxheight,0 quality  FROM
MULTIMEDIA join stock on wrefid = wstockid 
join imp_link l on l.wstockid = stock.wstockid and l.IMP_SOURCEID = <@IMP_SOURCEID@>
where WREFID = <@WSTOCKID@> and STYPE = 'STOCK' and (SPATH like 'link:%' or SPATH like 'file:%') 
and (   SGROUP = 'products_subimage6' )
