visual foxpro 98 working with cursores and brows, and loop for, for add columns - cursor

*!* TransForm(m.TCuatro,"#Z 999,999,999") + " "
*!* CDate("mx",Val(Right(Allt(field(4,"_Actual")),2)),Val("20"+SubStr(Allt(field(3,"_Actual")),2,2))) + " N(15,2)," + ;
*!* CDate("mx",Val(Right(Allt(field(5,"_Actual")),2)),Val("20"+SubStr(Allt(field(4,"_Actual")),2,2))) + " N(15,2)," +
CadExel = CDate("mx",Val(Right(Allt(field(2,"_Actual")),2)),Val("20"+SubStr(Allt(field(2,"_Actual")),2,2))) + " N(15,2)," + ;
"Promedio N(15,2), " + ;
"Cuota" + CDate("mx",__Mes,__Ano) + " N(12), " + ;
"VsProm N(12,2), " + ;
"Dobles N(12), Triples N(12), Fuera C(6)"
*!* CDate("mx",Val(Right(Allt(field(6,"_Actual")),2)),Val("20"+SubStr(Allt(field(5,"_Actual")),2,2))) + " N(12),"
*!* Padl(CDate("mx",Val(Right(Allt(field(4,"_Actual")),2)),Val("20"+SubStr(Allt(field(4,"_Actual")),2,2))),14) + " " + ;
*!* Padl(CDate("mx",Val(Right(Allt(field(5,"_Actual")),2)),Val("20"+SubStr(Allt(field(5,"_Actual")),2,2))),14) + " " +
TitNF = Padl(CDate("mx",Val(Right(Allt(field(3,"_Actual")),2)),Val("20"+SubStr(Allt(field(3,"_Actual")),2,2))),14) + " " + ;
Padl("Promedio",14) + " " + ;
Padl("Cuota",11) + " " + ;
Padl("VsAA",11) + " " + ;
Padl("Dobles",11) + " " + ;
Padl("Triples",11) + " " + ;
Padl("Rango",5) + " "
*!* Padl(CDate("mx",Val(Right(Allt(field(6,"_Actual")),2)),Val("20"+SubStr(Allt(field(6,"_Actual")),2,2))),11) + " "
Select * From __Cadena Order By Que Into Cursor __Paso
Select __Cadena
Zap
Select __Paso
Cad = "insert into __Cadena Values ( "
For i= 1 To FCount()
Cad = Cad + "__Paso." + Allt(Field(i,"__Paso")) + ","
EndFor
Cad = Left(Cad,Len(Cad)-1) + ")"
Go Top
Do While !Eof()
&Cad
Select __Paso
Skip
EndDo
Select __Paso
Use
*!* Set ClassLib To MyTool
*!* Barra = CreateObject("MiBarra")
*!* Barra.Dock(0)
*!* Barra.Show
*!* Define Class MiBarra As MyToolBar
*!* EndDefine
*!* Read Events
Select __Cadena
Go Top
Do vfreport With "Premier", TitNF , " Cuotas Club-Premier" + " de " + cDate("my",__Mes,__Ano) + IIf(__EsCF," (CF)"," (UV) "),"("+Allt(m.xNomPunto)+")", "Cuotas",;
CadExel,"",.F.,.F.,1,1,2,1,.F.,.F.,0
well that code is the final part for create this:
so you could see a column call a column call "mar08" which is
Marzo 2008 or "march 2008", well at this example i have a column,
but in part of code it gets to have 3 ór plus columns so i need add this lines for every column:
this code for a new column
CDate("mx",Val(Right(Allt(field(3,"_Actual")),2)),Val("20"+SubStr(Allt(field(2,"_Actual")),2,2))) + " N(12)," + ;
and this code for data of this column
Padl(CDate("mx",Val(Right(Allt(field(3,"_Actual")),2)),Val("20"+SubStr(Allt(field(3,"_Actual")),2,2))),11) + " " + ;
my question is
How can i do a loop for, for add automatically the code for columns, and data?
i am newbie on visual fox 98

If I understand what you are asking here is how you might do it...
CadExel = ""
TitNF = ""
FOR X = 1 TO n (where n is the number of columns you want to add)
CadExel = CadExel + CDate("mx",Val(Right(Allt(field(3,"_Actual")),2)),Val("20"+SubStr(Allt (field(2,"_Actual")),2,2))) + " N(12),"
TitNF = TitNF + Padl(CDate("mx",Val(Right(Allt(field(3,"_Actual")),2)),Val("20"+SubStr(Allt(field(3,"_Actual")),2,2))),11) + " "
ENDFOR
CadExel = CadExel + ;
"Promedio N(15,2), " + ;
"Cuota" + CDate("mx",__Mes,__Ano) + " N(12), " + ;
"VsProm N(12,2), " + ;
"Dobles N(12), Triples N(12), Fuera C(6)"
TitNF = TitNF + ;
Padl("Promedio",14) + " " + ;
Padl("Cuota",11) + " " + ;
Padl("VsAA",11) + " " + ;
Padl("Dobles",11) + " " + ;
Padl("Triples",11) + " " + ;
Padl("Rango",5) + " "
Basically you would concatenate your columns into CadEx and your column data into TitNF from within a FOR loop. 'X' is the variable that gets incremented on every iteration so you might need to use that somewhere within the CadExel and TitNF variables to change a portion of the expression.
If I am way off on this then maybe this will at least give you an idea of on how use the FOR loop to build the column and column data you are looking for.

Related

TableAPI SQL left join error "doesn't support consuming update and delete changes which is produced by node Join(joinType=[LeftOuterJoin]..."

Need to left join 2 data streams and the Table API throws an exception during starting the Flink app.
It is needed to calculate based on 2 different windows on a same input stream. So eventually the 2 calculated tables/steams need to be joined.
If I use "join" instead of using "left join" the start-up error disappears. Any idea how I can solve it? Is "left join" not supported?
Below is the exception:
org.apache.flink.client.program.ProgramInvocationException: The main method caused an error: Table sink 'default_catalog.default_database.Unregistered_DataStream_Sink_1' doesn't support consuming update and delete changes which is produced by node Join(joinType=[LeftOuterJoin], where=[((userId = userId0) AND (eventEpoch = eventEpoch0))], select=[userId, eventEpoch, AVG_VALUE_A, FIRST_VALUE_B, LAST_VALUE_B, FIRST_EVENTTIME, LAST_EVENTTIME, userId0, eventEpoch0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])\n\tat org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:372)\n\tat org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:222)\n\tat
Below is the code snippet.
Table inputTable = tableEnv.fromDataStream(
inputStream,
Schema.newBuilder()
.columnByExpression("rowtime", "CAST(eventTime AS TIMESTAMP(3))")
.watermark("rowtime", "rowtime - INTERVAL '" + WATERMARK_DELAY_IN_SECOND + "' SECOND")
.build());
//Register the table for use in SQL queries
tableEnv.createTemporaryView("InputTable", inputTable);
Table resultTable = tableEnv.sqlQuery(
"SELECT " +
" userId," +
" eventEpoch," +
" AVG(valueA) OVER w1 AS AVG_VALUE_B" +
" FROM InputTable " +
" WINDOW w1 AS (" +
" PARTITION BY userId ORDER BY rowtime" +
" RANGE BETWEEN INTERVAL '" + INTERVAL_A + "' SECOND PRECEDING AND CURRENT ROW)"
);
Table resultTable2 = tableEnv.sqlQuery(
"SELECT " +
" FIRST_VALUE(valueB) OVER w1 AS FIRST_VALUE_B," +
" LAST_VALUE(valueB) OVER w1 AS LAST_VALUE_B," +
" FIRST_VALUE(eventEpoch) OVER w1 AS FIRST_EVENTTIME," +
" LAST_VALUE(eventEpoch) OVER w1 AS LAST_EVENTTIME," +
" userId, eventEpoch" +
" FROM InputTable" +
" WINDOW w1 AS (" +
" PARTITION BY userId ORDER BY rowtime" +
" RANGE BETWEEN INTERVAL '" + INTERVAL_B + "' SECOND PRECEDING AND CURRENT ROW)"
);
tableEnv.createTemporaryView("ResultTable1", resultTable);
tableEnv.createTemporaryView("ResultTable2", resultTable2);
Table resultTable3 = tableEnv.sqlQuery(
"SELECT ResultTable1.*," +
" ResultTable2.FIRST_VALUE_B," +
" ResultTable2.LAST_VALUE_B," +
" ResultTable2.FIRST_EVENTTIME," +
" ResultTable2.LAST_EVENTTIME" +
" FROM ResultTable1" +
" LEFT JOIN ResultTable2" +
" ON ResultTable1.userId = ResultTable2.userId" +
" AND ResultTable1.eventEpoch = ResultTable2.eventEpoch"
);

How can I generating a table with code below

A long loop
for(int a = 1,b = 10, c = 11, d = 20, e = 21, f = 30, a <= 10, a++, b--, c++, d--, e++, f--)
System.out.println(a + " " + b + " " + c + " " + d + " " + e + " " + f);
Update your code as below and you will have your expected table.
for(int a=1,b=10, c=11, d=20, e=21,f=30; a<=10;a++,b--,c++,d--,e++,f--)
System.out.println(a+ " " +b+ " " +c+ " "+d+ " "+e+ " "+f);
}
That is after the declarations you should have a ; not a , . And then, again after the condition also you should have a ; not a ,

ERROR: The conversion of string " Declare #RepInt=" to double is not valid

I have this query
Dim count as integer = 4
Dim sql As String = " DECLARE #rep INT = " + count + "; " + _
" WITH cte AS " + _
" ( " + _
" SELECT TOP (#rep) " + _
" ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS N " + _
" FROM sys.All_Columns ac1 " + _
" CROSS JOIN sys.ALL_Columns ac2 " + _
" ) " + _
" SELECT t.Barcode" + _
" FROM A_Documents t " + _
" CROSS JOIN cte " + _
" where idDocument = 'doc-123456' " + _
" ORDER BY t.Barcode desc; "
If I put a number without a var, ist works:
Dim sql As String = " DECLARE #rep INT = 4; " + _
But when I put my COUNT var, is not work:
Dim sql As String = " DECLARE #rep INT = " + count + "; " + _
And appears this error message:
The conversion of string " Declare #RepInt=" to double is not valid
that's the expected behaviour of the + operator.
when you feed a number variable to it then the system attempts to convert all the other objects to that numeric type to complete the addition, hence the exception.
imho this is a feature because allows you to exactly know what you are concatenating.
the solution:
Dim sql As String = " DECLARE #rep INT = " + count.ToString + "; " + _
When you try to add a string and a number, it will try to convert the string to a number. You can use the & operator instead, which will convert anything that isn't a string to a string:
Dim sql As String = " DECLARE #rep INT = " & count & "; " + _

Operator '<>' is not defined for type 'DBNull' and string ""

while using the given below code showing one error. The error is : Operator '<>' is not defined for type 'DBNull' and string "". Help me to find a proper solution. Thank You.
Code:
If sdr1.Read Then
If sdr1(1) <> "" Then
NameLabel.Text = sdr1(0).ToString + " " + sdr1(1).ToString + " " + sdr1(2).ToString
Else
NameLabel.Text = sdr1(0).ToString + " " + sdr1(2).ToString
End If
dept_id.Text = sdr1(3)
End If
sdr1.Close()
You need to check whether the data you are comparing is NULL or not before you use it inside any operation:
If sdr1.Read Then
If Not IsDbNull(sdr1(1)) Then
If sdr1(1) <> "" Then
NameLabel.Text = sdr1(0).ToString + " " + sdr1(1).ToString + " " + sdr1(2).ToString
Else
NameLabel.Text = sdr1(0).ToString + " " + sdr1(2).ToString
End If
End If
dept_id.Text = sdr1(3)
End If
sdr1.Close()
or you can simply use
If sdr1.Read Then
If Not IsDbNull(sdr1(1)) Then
NameLabel.Text = sdr1(0).ToString + " " + sdr1(1).ToString + " " + sdr1(2).ToString
Else
NameLabel.Text = sdr1(0).ToString + " " + sdr1(2).ToString
End If
dept_id.Text = sdr1(3)
End If
sdr1.Close()
Your column contains a null value. You have to check for nullness before trying to do other comparisons.
So...
If DBNull.Value Is sdr1(1) Then
' Got a null value from the database.
End If
If you don't care about whether the value is null, or empty - just want to treat them the same...
If String.IsNullOrEmpty(sdr1(1)) Then
' The value is either null or empty.
End If
Use If sdr1(1) IsNot "" Then or If Not IsDBNull(sdr1(1)) Then instead for <> that will give you better result
Use String.IsNullorEmpty instead for checking the same
Ex:-
If Not String.IsNullOrEmpty(x) Then
'Do Something
End If
Use instead of If function
try
If sdr1.Read Then
If Not IsDbNull(sdr1(1)) Then
NameLabel.Text = sdr1(0).ToString + " " + sdr1(1).ToString + " " + sdr1(2).ToString
Else
NameLabel.Text = sdr1(0).ToString + " " + sdr1(2).ToString
End If
dept_id.Text = sdr1(3)
End If
Catch ex As Exception
end try

Insert DBNUll.value to database for a int field?

I am unable to insert null in my database for the OrderMealDealItemID when the OrderMealdealItemID is null in the database for the below query.
string insertStatementDressing = null;
insertStatementDressing = #"Insert into OrderDressing(SrNo,DressingID,OrderItemID,OrderID,ProductID,OrderMealDealItemID,IsDeleted,IsApplied,Amount,IsPriceApplied)
values('" + odiDress.SrNo + "'," + odiDress.DressingID + "," + odiDress.OrderItemID + "," +
latestOrderID_onLocal + "," + odiD.ProductID + "," +
odiDress.OrderMealDealItemID??DBNull.Value
+ "," + odiDress.IsDeleted + "," + odiDress.IsApplied + "," + odiDress.Amount + "," + odiDress.IsPriceApplied + ")";
db_local.ExecuteStoreCommand(insertStatementDressing);
When i execute this query it get converts to follwing but not a complete executable string that can e accepted by database.
Insert into OrderDressing(SrNo,
DressingID,
OrderItemID,
OrderID,
ProductID,
OrderMealDealItemID,
IsDeleted,
IsApplied,
Amount,
IsPriceApplied)
values('02785d81-dc9f-4bf1-8050-7498bcb427c7',38,1,20,3,
Because you are creating the SQL string manually you also need to create the NULL value manually. Try this:
insertStatementDressing = #"Insert into OrderDressing(SrNo,DressingID,OrderItemID,OrderID,ProductID,OrderMealDealItemID,IsDeleted,IsApplied,Amount,IsPriceApplied)
values('" + odiDress.SrNo + "'," + odiDress.DressingID + "," + odiDress.OrderItemID + "," +
latestOrderID_onLocal + "," + odiD.ProductID + "," +
odiDress.OrderMealDealItemID.HasValue ? odiDress.OrderMealDealItemID.Value.ToString() : "NULL" + "," + odiDress.IsDeleted + "," + odiDress.IsApplied + "," + odiDress.Amount + "," + odiDress.IsPriceApplied + ")";
Note that you should avoid writing queries like this as they are vulnerable to SQL injection (among other issues)

Resources