Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Monday, November 18, 2013

update_recordset , insert_recordset, Delete records and select record of SQL in Dynamic AX 2012


//Select query in Dynamic AX 2012
 MyTable myTableBuffer;
;
Select myTableBuffer
where field1 == 0;
//use while select for multiple select

// Update query in Dynamic AX 2012

MyTable myTableBuffer;
;
update_recordset myTableBuffer
setting
    field1 = 1,
    field2 = fieldX + fieldY
where field1 == 0;

//Delete query in Dynamic AX 2012
 
static void DeleteMultiRow1aJob(Args _args)
{
    MyWidgetTable tabWidget;
    ;
    delete_from tabWidget
        where tabWidget .quantity <= 100;
}
 

// Insert query in Dynamic AX 2012
insert_recordset myTable (Field1, Field2)
    Field1= “QWERTyuioP”
Field2 = “ASDFghjkl” ;
 


Thursday, November 14, 2013

To take complete back up of SQL in single code

DECLARE @name VARCHAR(100)
DECLARE @path VARCHAR(256)
DECLARE @fileName VARCHAR(256)
DECLARE @fileDate VARCHAR(20)
SET @path = 'G:\BACKUP'
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) + '_' +REPLACE(CONVERT(VARCHAR(20),GETDATE(),108),':','')
DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb')
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName
FETCH NEXT FROM db_cursor INTO @name
END
CLOSE db_cursor
DEALLOCATE db_cursor

SQL code to upate one Legal entity banner to all the legal entity in D365

 Hi, update companyimage set  companyimage.Image  = companyimageA.Image  from  ( select Image from companyimage where dataAreaid = 'USF...