hi Crispin
The code Is below
str query,FDate,TDate;
Set permissionSet = new Set(Types::Class);
Connection connection;
Statement statement;
;
Fdate = date2str(BegDate, 321, DateDay::Digits2, DateSeparator::Hyphen, DateMonth::Digits2, DateSeparator::Hyphen, DateYear::Digits4, DateFlags::None);
TDate = date2str(EDate, 321, DateDay::Digits2, DateSeparator::Hyphen, DateMonth::Digits2, DateSeparator::Hyphen, DateYear::Digits4, DateFlags::None);
// Set the SQL statement
query = "DECLARE @DATE DATE";
query += " SET @DATE = '" + Fdate + "'";
query += " truncate table ItemSOHRep";
query += " WHILE @DATE <='" + TDate + "'";
query += " BEGIN";
query += " INSERT INTO ItemSOHRep ";
query += " SELECT ITEMID, @DATE, sum(iTrans.QTY) from INVENTTRANS as iTrans inner join INVENTDIM as iDim on iDim.INVENTDIMID = iTrans.INVENTDIMID";
query += " inner join INVENTLOCATION Loc On Loc.INVENTLOCATIONID = iDim.INVENTLOCATIONID";
query += " where ";
query += " iTrans.DATAAREAID IN (SELECT * FROM [dbo].[fnSplit]('" + Comps + "',',')) ";
query += " AND ";
query += " iDim.DATAAREAID IN (SELECT * FROM [dbo].[fnSplit]('" + Comps + "',',')) ";
if(Itm != "")
query += " and iTrans.ITEMID IN (SELECT * FROM [dbo].[fnSplit]('" + Itm + "',',')) ";
query += " and";
query += " loc.GOODWAREHOUSE = 1 ";
query += " AND ITEMID NOT LIKE 'ZZZ%'";
query += " and ";
query += " ((iTrans.DATEINVENT <> '' and iTrans.DATEINVENT <= @DATE ) OR";
query += " (iTrans.DATEINVENT = '' and iTrans.DATEPHYSICAL <> '' and iTrans.DATEPHYSICAL <= @DATE ))";
query += " group by iTrans.ITEMID";
query += " SET @DATE = DATEADD(dd,1,@DATE)";
query += " END";
connection = new Connection();
statement = connection.createStatement();
permissionSet.add(new SqlStatementExecutePermission(query));
CodeAccessPermission::assertMultiple(permissionSet);
statement.executeUpdate(query);
CodeAccessPermission::revertAssert();