AX 2012 View computed column returning Null - axapta

I have a View in AX with a computed column:
private static server str qty()
{
#define.THEN(" THEN ")
#define.SINGLE_QUOTE("'")
return 'CASE T2.ReturnStatus ' +
' WHEN ' + int2str(enum2int(ReturnStatusLine::None)) + #THEN + '-1 * T3.UnitValue' +
' WHEN ' + int2str(enum2int(ReturnStatusLine::Awaiting)) + #THEN + '-1 * T3.UnitValue' +
' WHEN ' + int2str(enum2int(ReturnStatusLine::Registered)) + #THEN + '-1 * T3.UnitValue' +
' ELSE ' + "(T3.UnitValue / T2.ExpectedRetQty * (SELECT TOP 1 SUM(cpst.Qty) as RcvQty from custPackingSlipTrans as cpst where cpst.InventTransId = T2.InventTransId and cpst.dataAreaId='" + curext() + "')) * -1" +
' END';
}
It works great, except the past week or so the column is returning NULL when it should not be. This is fixed simply by going into the AOT and syncing this view, after that the column has a valid value. But we're having to do this almost daily.
Any ideas?

Related

SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 15596 and this is thread id 10564

tableName = entityName + 's'
columnName = entityName
cursor.execute('SELECT rowid FROM ' + tableName + ' WHERE ' + columnName + ' = ?', (text,))
row = cursor.fetchone()
if row:
return row[0]
else:
cursor.execute('INSERT INTO ' + tableName + ' (' + columnName + ') VALUES (?)', (text,))
return cursor.lastrowid
Error:- cursor.execute('SELECT rowid FROM ' + tableName + ' WHERE ' +
columnName + ' = ?', (text,)) sqlite3.ProgrammingError: SQLite objects
created in a thread can only be used in that same thread. The object
was created in thread id 15596 and this is thread id 10564.
how i can solve this error.

MS Access - Combine varchar column with int column - ASP.net VB.net

I'm using an oledb connection string to connect my asp.net code to an access db
I can't seem to convert combine the 3 fields - ProductID(NUMBER)
ProductCode(TEXT), ProdDescription(TEXT)
Dim strQuery As String = "SELECT ProductID, (CAST(ProductID AS TEXT) + ' - '
+ ProductCode + ' - ' + ProdDescription) AS [Prod]
FROM [FG - End Product Codes]
ORDER BY ProductCode;"
I've also tried
(CAST(ProductID AS VARCHAR(10)) + ' - ' + ProductCode + ' - ' + ProdDescription) AS [Prod]
And
(CONVERT(ProductID, TEXT)) + ' - ' + ProductCode + ' - ' + ProdDescription) AS [Prod]
AND
(CAST(ProductID) AS VARCHAR(10)) + ' - ' + ProductCode + ' - ' + ProdDescription) AS [Prod]
AND
(CAST([ProductID] AS TEXT) + ' - ' + [ProductCode] + ' - ' + [ProdDescription]) AS [Prod]
Error msg: System.Data.OleDb.OleDbException:
'IErrorInfo.GetDescription failed with E_FAIL(0x80004005).'
error code : -2147467259
I seen the same error in another question but theirs seem to have some reserve keyword problem, If mine is the same, what is My reserved Keyword and where is it in my code?
thanks in advance
That's because you try to use T-SQL against Access which uses Access SQL. So, try this:
Dim strQuery As String = "SELECT ProductID, ProductID & ' - ' &
ProductCode & ' - ' & ProdDescription AS [Prod]
FROM [FG - End Product Codes]
ORDER BY ProductCode;"

Record is not updating in a phonegap sqlite storage given in a particular query

This is the query which is update single record in a table.
Where FriendTable.tablename and other column name is define a constant file.
Values which is to update is store in Friend variable.
FriendTable.updateValues=function(Friend,successCallback,errorCallback){
var query = 'update '+ FriendTable.tablename + ' set ' + FriendTable.lat + '=?,' + FriendTable.lon + '=?,' + FriendTable.locaddr + '=?,' + FriendTable.locts + '=? where ' + FriendTable.phonenumber + " =?";
app.dbobj.transaction(function (tx) {
console.log('Update Friend record :: ' + query);
console.log('Friend data :: ' + Friend.toString());
tx.executeSql(query,[Friend.lat,Friend.lon,Friend.locaddr,Friend.locts,Friend.phonenumber],successCallback,errorCallback);
});
}

SQL Server Data type change from Numeric(7,3) to Varchar(20)

I have a field (dose_str) that needs to be changed from Numeric(7,3) to Varchar(20). I would like to know if there will be a need to change the query below (especially this portion SELECT (convert(varchar,cast(Prot_det.dose_str as float)) ) in the code of my application.
myCommand.CommandText = "
SELECT (convert(varchar,cast(Prot_det.dose_str as float)) + ' '
+ dose_unit + ' ' + dose_form_comment + ' ' + dose_mult) as Dose_str
from
Prot_det,
dosage_form
where
Protocol_num = '" & lblProtocol.Text & "' and
nsc_num = " & lstNSC.SelectedValue & " and
prot_det.dose_form = dosage_form.dose_form"
After changing the datatype of the column, you will be able to change this:
(convert(varchar,cast(Prot_det.dose_str as float))
to this:
(Prot_det.dose_str)
And I would recommend that you do.

Custom dynamic paging using stored procedure in asp.net

CREATE PROCEDURE [dbo].[sp_GetPageWiseData]
(
#tableName sysname,
#orderColumn nvarchar(100),
#PageIndex INT = 1,
#PageSize INT = 10,
#RecordCount varchar(10) OUTPUT
)
AS
BEGIN
SET NOCOUNT ON;
DECLARE #query varchar(2000),
#minimumIndex varchar(5),
#maximumIndex varchar(5)
SET #minimumIndex=convert(varchar,(#PageIndex - 1) * #PageSize + 1)
SET #maximumIndex=convert(varchar,#PageIndex * #PageSize)
SET #query='SELECT ROW_NUMBER() OVER(ORDER BY ' + #orderColumn + ' ASC)AS RowNumber,* INTO #Results FROM ' + #tableName + ';
SELECT ' + #RecordCount + '=COUNT(*) FROM #Results;
SELECT * FROM #Results WHERE RowNumber BETWEEN ' + #minimumIndex + ' AND ' + #maximumIndex + ';
DROP TABLE #Results'
Exec (#query)
END
Here is the problem is when the procedure is executed, output parameter #RecordCount shows NULL value.
WHY?
Please explain.
Thanks
Your query must be like this:
SET #query='SELECT ROW_NUMBER() OVER(ORDER BY ' + #orderColumn + ' ASC)AS RowNumber,* INTO #Results FROM ' + #tableName + ';
SELECT #RecordCount =COUNT(*) FROM #Results;
SELECT * FROM #Results WHERE RowNumber BETWEEN ' + #minimumIndex + ' AND ' + #maximumIndex + ';
DROP TABLE #Results';
But here system will ask you to declare the variable, #RecordCount
so you can do it like this by returning 2 datasets from the query;
SET #query='DECLARE #RecordCount varchar(10); SELECT ROW_NUMBER() OVER(ORDER BY ' + #orderColumn + ' ASC)AS RowNumber,* INTO #Results FROM ' + #tableName + ';
SELECT #RecordCount =COUNT(*) FROM #Results;
SELECT * FROM #Results WHERE RowNumber BETWEEN ' + #minimumIndex + ' AND ' + #maximumIndex + ';
SELECT #RecordCount AS TOTALRECORDS;
DROP TABLE #Results';
I think you cant use it on this way. It's like concatanation not a value assign method. I think you should handle it in two steps, something like this:
SET #query='SELECT ROW_NUMBER() OVER(ORDER BY ' + #orderColumn + ' ASC)AS RowNumber,* INTO #Results FROM ' + #tableName + ';'
Exec (#query)
SELECT #RecordCount =COUNT(*) FROM #Results
SET #query='SELECT * FROM #Results WHERE RowNumber BETWEEN ' + #minimumIndex + ' AND ' + #maximumIndex + ';
DROP TABLE #Results'
Exec (#query)

Resources