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?
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);
});
}
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.
Hello i have an sql query which uses a Dateformat. This code will run on different servers but every server have different dateformats. sometimes yyyy-MM-dd and sometimes yyyy-dd-MM.
I tried to read the userlanguage to choose the correct query. but it doesnt work properly.
Do you know any other good solution to solve my problem ?
Thanks in advance
Dim Systemsprache as String
Systemsprache = Request.UserLanguages(0)
If String.Compare(Systemsprache, "de-DE") = 0 Then
sqlcmd = "SELECT convert(varchar(8) , [VON],108) as [VON] ,convert(varchar(8) , [BIS],108) as [BIS] FROM [RESERVIERUNGRAUM] where RAUM_ID =" + hCurrRaumID.Value + " and VON >='" + Date.Parse(wiDateVON1.Value).ToString("yyyy-MM-dd") + "' and BIS <'" + Date.Parse(wiDateVON1.Value).AddDays(1).ToString("yyyy-MM-dd") + "'"
Else
sqlcmd = "SELECT convert(varchar(8) , [VON],108) as [VON] ,convert(varchar(8) , [BIS],108) as [BIS] FROM [RESERVIERUNGRAUM] where RAUM_ID =" + hCurrRaumID.Value + " and VON >='" + Date.Parse(wiDateVON1.Value).ToString("yyyy-dd-MM") + "' and BIS <'" + Date.Parse(wiDateVON1.Value).AddDays(1).ToString("yyyy-dd-MM") + "'"
End If
If I remember correctly, you can use the universal format '#yyyy-mm-dd#' regardless of the server default date format.
string updateIncomeData = #"INSERT INTO TEAM_FUNDS_DETAILS("
+ "COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR)"
+ "VALUES(" + Convert.ToInt32(TeamFundDetailsEnumClass.ComponentType.Income)
+ " , ?, ?,"
+ ddlYear.SelectedIndex + ", " + ddlMonth.SelectedIndex + ")"
This parametrized query gives me an exception that tells me that there is an error near "?". What is the error. Please correct it.
I am purely guessing but should it be year.selecteditem? not selectedindex?
I don't understand why you would want to mix up the parameter substitution.
Specify all five columns as parameters and set the values that way.
"INSERT INTO TEAM_FUNDS_DETAILS " +
"(COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR) " +
"VALUES(? , ?, ?,?, ?)"
You must set the parameterized values (the ones with the question mark). Here is a similar example in VB.NET:
' Make a Command for this connection
' and this transaction.
Dim cmd As New OleDb.OleDbCommand( _
"SELECT * FROM People WHERE FirstName=? AND " & _
"LastName=?", _
connUsers)
' Create parameters for the query.
cmd.Parameters.Add(New _
OleDb.OleDbParameter("FirstName", first_name))
cmd.Parameters.Add(New OleDb.OleDbParameter("LastName", _
last_name))
If you don't want to use parameterized queries, just substitute the question mark with the default value, or the variable with the value:
string updateIncomeData = #"INSERT INTO TEAM_FUNDS_DETAILS("
+ "COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR)"
+ "VALUES(" + Convert.ToInt32(TeamFundDetailsEnumClass.ComponentType.Income)
+ " , '', 0,"
+ ddlYear.SelectedIndex + ", " + ddlMonth.SelectedIndex + ")"
or
string updateIncomeData = #"INSERT INTO TEAM_FUNDS_DETAILS("
+ "COMPONENT_TYPE,COMPONENT_NAME,COMPONENT_AMOUNT, YEAR_FOR, MONTH_FOR)"
+ "VALUES(" + Convert.ToInt32(TeamFundDetailsEnumClass.ComponentType.Income)
+ " , '" + myComponentName + "', " + myComponentAmount,"
+ ddlYear.SelectedIndex + ", " + ddlMonth.SelectedIndex + ")"
ddlMonth.SelectedItem.Value