While loop in query is going under infinite loop
Declare
@StartDate_in date,
@EndDate date
Set @StartDate_in = cast('2000-01-01' as date)
Set @EndDate = cast('2010-12-31' as date)
declare @month int
declare @year int
declare @endyear int
declare @startdate date
set @startdate= @startdate_in
set @month = month(@StartDate_in)
set @year= year(@StartDate_in)
set @endyear= year(@EndDate)
while @year<=@endyear
Begin
while month(@startdate)<=12 and @year<=@endyear
begin
print (@year);
print (month(@startdate));
INSERT Into target
( YEAR,
MONTH,
MONTH_VAL,
L_DT,
U_DT,
S_DT,
E_DT
Values
( datepart(yyyy,@StartDate) ,
datepart(month,@StartDate) ,
substring(datename(month,@StartDate),1,3),
GETDATE(),
GETDATE(),
(GETDATE()-1),
null
set @StartDate = dateadd(month,1,@StartDate);
set @month=1;
end
set @year=@year+1;
print (@year);
print (@month);
end
The query although with exit condtion given in the while loop is not ending and executing infinetly
ddl of target
CREATE TABLE target(
[TIME_ID] [int] IDENTITY(1,1) NOT NULL,
[START_DT] [date] NULL,
[E_DT] [date] NULL,
[L_DT] [datetime] NULL,
[U_DT] [datetime] NULL,
[YEAR] varchar (5) NULL,
[MONTH] varchar(5) NULL,
[MONTH_VAL] [varchar](5) NULL
) ON [PRIMARY]
GO
Mudassar
Try followings:Declare
@StartDate_in date,
@EndDate date
Set @StartDate_in = cast('2000-01-01' as date)
Set @EndDate = cast('2010-12-31' as date)
declare @month int
declare @year int
declare @endyear int
declare @startdate date
declare @innerloopyear int
set @startdate= @startdate_in
set @month = month(@StartDate_in)
set @year= year(@StartDate_in)
set @endyear= year(@EndDate)
set @innerloopyear = @year
while @year<=@endyear
Begin
while month(@startdate)<=12 and @year>=@innerloopyear
begin
print (@year);
print (month(@startdate));
INSERT Into target
( YEAR,
MONTH,
MONTH_VAL,
L_DT,
U_DT,
S_DT,
E_DT
Values
( datepart(yyyy,@StartDate) ,
datepart(month,@StartDate) ,
substring(datename(month,@StartDate),1,3),
GETDATE(),
GETDATE(),
(GETDATE()-1),
null
set @StartDate = dateadd(month,1,@StartDate);
set @innerloopyear = YEAR(@startdate)
set @month=1;
end
print 'hello'
set @year=@year+1;
--set @StartDate = DATEADD(year,1,@StartDate)set @innerloopyear = @year
print (@year);
print (@month);
end
I have formatted change in "Bold".
Similar Messages
-
ABAP-query going in infinite loop
Hello all,
I have one on abap-query in which i am displaying data for delivery details that is table LIKP and LIPS.
In this query i also have some code to get the sale order details from the the delivery details.
I have also used one FM module in this query as well as select endselet stamt.
When i run my quey it i going in infinite loop. I am not getting any thing . Each time i have to exit the screen.
Can anyone please tell me wat is the problem, why it is going in infinite loop.
Thanks and regards
Sachin yadavthanks for your help,
But may i know how to display my internal table data to out put screen.
As i am new to the query i do not know how to display internal table data to report along with my data coming from ABAp-query.
for eg i have three field to display suppose A , B and C.
Field A and B are coming from query and i have to display field C from internal table.
How to do that
thanks in advance -
I am migrating a project from Java 1.3 to Java 1.7 update 25 and there is one search button functionality in which search is performed correctly but the UI flickers continuously because EventdispatchThread's pumpEventsForFilter goes to infinite while loop.
This same code works correctly in java 1.3.
Below is the part of the code related to searchbutton. Can you please suggest regarding this because the issue is within java api and not sure how to solve this.
SearchButton.java:
private JButton searchButton;
private String textsearchButton =
search.util.Language.getString("buttonStartSearch");
searchButton = new JButton(textsearchButton);
buttonPanel.add(searchButton);
searchButton.addActionListener(this);
searchButton.addActionListener(actionListener);
actionListener.actionPerformed(
new ActionEvent(
searchButton,
ActionEvent.ACTION_PERFORMED,
"toFront"));
actionListener.actionPerformed(
new ActionEvent(
searchButton,
ActionEvent.ACTION_PERFORMED,
"searchComplete"));
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if (hasSearch) {
actionListener.actionPerformed(
new ActionEvent(
searchButton,
ActionEvent.ACTION_PERFORMED,
"searchComplete"));
else {
actionListener.actionPerformed(
new ActionEvent(
searchButton,
ActionEvent.ACTION_PERFORMED,
"search"));
searchButton.setEnabled(!hasSearch && hasCriterions());
public void actionPerformed(ActionEvent ae) {
Object source = ae.getSource();
else if (source == searchButton)
startSearch();
else if (source == exportButton)
exportSearch();
else { // ActionEvents from the panels occur
changesOccured();
EventDispatchThread:
void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) {
addEventFilter(filter);
doDispatch = true;
//This while goes to infinite loop
[b] [color=red]while (doDispatch && !isInterrupted() && cond.evaluate()) {
pumpOneEventForFilters(id);
}[/color][/b]
removeEventFilter(filter);Please provide your code example as SSCCE . I'm not going to spent time guessing what your application code (other than shown) meigt do or not do.
bye
TPD -
Hey there! I'm trying to do some data input validation but I haven't been able to figure it out. First I need to check if the user entered anything, that one works. Then I need to check if what the user entered was a number. But I'm getting an infinite while loop in when I try to validate if the first character entered is a letter. . . .
Thanks for your help!
public class methods
public static void main(String args[]) throws IOException
String input ="";
int qoh=0;
boolean error=true;
Scanner keyboard = new Scanner (System.in);
//while (error)
// error=true;
while (error==true)
System.out.print("\nEnter Quantity on Hand: ");
input = keyboard.nextLine();
if (input.length() <1)
System.out.println("\n**ERROR06** - Quantity on hand must be between 0 and 500");
error=true;
System.out.println(qoh);
System.out.println(input);
else
error=false;
error = true;
while (error==true)
if (Character.isLetter(input.charAt(0)))
System.out.println("\n**ERROR06** - Quantity on hand must be between 0 and 500");
error=true;
System.out.println(qoh);
System.out.println(input);
else
qoh = Integer.parseInt(input);
error=false;
}1. add in breakpoints to your program.
Eg. put print statements before and after loops to confirm which loop is producing the inf loop error.
also add in print statements in your if and else blocks.
2. You should consider using keyboard.next() instead of nextLine()
Eg. how are you going to handle "500 orange crush"?
3. I have a feeling that the real problem lies at the 2nd loop where you tried to do a parseInt
What happens if you have "5lmao" charAt(0) check is passed, but it wont produce a int will it?
You might want to loop through every char in the input string to confirm they are a number.
4. I suggest
If(input.length() > 0) error = false
else print msg
OR
assume no errors before loop.
if(length() <1) error=true
else error = false
5. use the keyword "break". By that i mean set up your loop to be infinite loops, use the break operator under specified condition (error=false)
I didn't identify the error for you, but i'd say the above methods should help you with your problem -
Do While loop with query?
There seems to be no way to do a do-while loop without using
Cfscript.
Is there a way to place a cfquery inside cfscript?How so?
The algorithm I'm trying to write is sort of recursive.
Basically, I have a column in a table generated like so:
Row 1: Sum of (account 1, account 2)
Row 2: Sum of (account 3, account 4)
Row 3: sum of rows 1-2
Row 4: Sum of (account 5, account 6)
Row 5: Sum of rows 3-4
So basically, I'm trying to query for all of the accounts
that make up row 5 (which in this case is ALL of the accounts). It
looks like I'm going to have to work backwards from the starting
row (5) and keep checking the rows that its composed of until I hit
some base case (no more summation rows?) -
How to out from infinite while loop in sub VI
Dear Sir,
how to out from infinite while loop in sub VI from main VI
attached photo for solution but I can't understand it and i can't find the function in photo
please help
Attachments:
stop_subVI_frm_main.JPG 36 KBAsking how to get out of an infinite loop is like asking how to find the end of a circle. I'm not trying to be sarcastic but by definition, if there is a way out of the loop, then it is not infinite. I think what you are asking is how to avoid creating an infinite loop. Is there something about the suggestions you have been given that you do not like? My favorite suggestion is the notifier but maybe you just need an example. Turn on context help and read about the notifier functions in the code below.
This is your top level VI
And this is your subVI
If this seems too complex then a global variable will work too. But what seems simpler can cause much more complex bugs. You can code fast and spend lots of time debugging or you can code slow and spend less time debugging. Personally I perfer writing productive code than looking for bugs any time.
=====================
LabVIEW 2012 -
Dynamic query in where clause while looping in an internal table.
Hi,
Had a small question : How can i make a dynamic query for the WHERE clause while looping at an internal table.
i want to implement a dynamic where clause query for the below example.
it_cfx_col is an internal table and wa_cfx_col is a work area for it_cfx_col
DATA :
i_cfx_col TYPE TABLE OF cfx_col,
wa_cfx_col LIKE LINE OF i_cfx_col.
DATA : count TYPE i VALUE 0.
DATA : l_where_clause TYPE string,
l_where_clause2 TYPE string,
l_name type string.
l_name = 'NANDANOM'.
l_scenario = 'collaboration'.
LOOP AT it_cfx_col INTO wa_cfx_col
WHERE CREATED_BY = l_name
AND SCENARIO = l_scenario.
count = count + 1.
some business logic implemented using the work area wa_cfx_col
endloop.
Now i want to write a dynamic query for the where clause.
DATA : count TYPE i VALUE 0.
DATA : l_where_clause TYPE string,
l_where_clause2 TYPE string,
l_name type string.
l_name = 'NANDANOM'.
l_scenario = 'collaboration'.
l_where_clause = 'CREATED_BY = l_name'.
l_where_clause2 = 'AND SCENARIO = l_scenario'.
if l_scenario is not initial.
CONCATENATE l_where_clause l_where_clause2
INTO l_where_clause SEPARATED BY space.
endif.
LOOP AT i_cfx_col INTO wa_cfx_col
WHERE (l_where_clause).
count = count + 1.
some business logic implemented using the work area wa_cfx_col
endloop.
when i compile this i get an error message as { Statement concluding with "...(l_where_clause)" ended unexpectedly}
Even i changed the initilization of the variable l_where_clause2 to [ l_where_clause2 = 'AND SCENARIO = l_scenario.'. ]
added the end of line demarkation ".", but still i got the same error message.
Is it a limtation in ABAP that i cannot write a dynamic query for the where clause while looping at an internal table?
Regards,
omHi savita,
there in no such 1 limitaion in abap for dynamic query .. i think the error meassge is only beacuse of your synatx delcartaion.
>> LOOP AT i_cfx_col INTO wa_cfx_col
WHERE (l_where_clause).
count = count + 1.
some business logic implemented using the work area wa_cfx_col
endloop.
afted delclarataion also , in the where statement you should specify both the field name and value bname
LOOP AT i_cfx_col INTO wa_cfx_col
WHERE l_where_clause = 'CREATED_BY = l_name' .
count = count + 1.
hope it helps.
regads
priya. -
REDO scanning goes in infinite loop and Too much ARCHIVE LOG
After we restart DATABASE, capture process REDO scanning goes in infinite loop and Too much ARCHIVE LOG being generated.
No idea whats going on.... otherwise basic streams functionality working fine.What's your DB version
-
I execute my progrem its goes to infinite loop?
Hi frnds,
I execute my program its goes to infinite loop? How can i stop that program, before goes to dump?why don't you put a break point before the loop and just check why it is not finishing up. u can always set conditions when to exit from such loops when required.
Loop ...
if some cond
exit.
endif
endloop. -
my daq 6008 wil not drop the 5V on a digital output after the VI is stopped, i have a digital signal going from the error out on the daq in the while loop to the error in on the daq outside the while loop and a boolean going to the data of the daq outside, but i can t seemto get it to work
i attached the block diagram so you can have a look
Attachments:
PID Temp control.docx 120 KB -
DECLARE
@databasename AS
NVARCHAR(128);
SET
@databasename =
(SELECT
MIN(name)
FROM sys.databases
WHERE
name NOT
IN ('master',
'model',
'msdb', 'tempdb'));
WHILE
@databasename IS
NOT NULL BEGIN
PRINT @databasename;
SET @databasename
= (SELECT
MIN(name)
FROM sys.databases
WHERE
name NOT
IN ('master',
'model',
'msdb', 'tempdb')
AND
name >
@databasename); END
Databases
A
B
C
D
I have question related to the above SQL statement, forgive me as I am unfamiliar with WHILE loops.
I understand that the query above finds the minimum database name, prints the value then finds the next database greater than the minimum.
What happens when it loops occurs, I know it prints the database name of the one it has found. In the example above it will be B. Will the @databasename be then set to B and the following query will be run so the @databasename will then be
set to C?
SELECT
MIN(name)
FROM sys.databases
WHERE
name NOT
IN ('master',
'model',
'msdb', 'tempdb')
AND
name >
@databasename);Yes. You run this query:
SET @databasename =
(SELECT MIN(name)
FROM sys.databases
WHERE name NOT IN ('master','model', 'msdb', 'tempdb'));
This gives you the first user database, alphabetically according to your system database. The WHERE clause filters out the system databases.
Then in the WHILE loop you do the same, with one condition added:
AND name > @databasename
So this gives the next user database alphabetically. But if there is no further database, the query returns NULL, and the condition in the WHILE statement will evaluate to FALSE, and the loop will terminate.
Erland Sommarskog, SQL Server MVP, [email protected] -
Can we execute a query in resultset while loop
can we execute a query in resultset while loop
for ex:
rs=st.executeQuery("SQL");
while(rs.next())
rs1=st.executequery("SQL1");
while(rs1.next())
}If you do this, you lose "rs". Create a second
Statement object for the other query.This is right. We have done it many times, It is not the issue as long as you use different statement with in the body of the loop -
Can we execute a query in resultset of while loop
can we execute a query in resultset while loop
for ex:
rs=st.executeQuery("SQL");
while(rs.next())
rs1=st.executequery("SQL1");
while(rs1.next())
}yup no problem..if it doesn work declare the second one as st1
-
Stuck inside an infinite While Loop :-/
Hi all,
When I write this program using the top-down structural method, it runs fine but when I use the call method inside the while loop, it doesn't test the "if" condition. It becomes a never-ending loop. :-/
import java.util.Random;
public class WhileLoop {
public static void main(String[] args) {
int random1;
Random die1 = new Random();
random1 = die1.nextInt(6) + 1;
WhileLoop r = new WhileLoop();
while (random1 != 5) {
if (random1 != 5) {
r.doRandom();
if (random1 == 5) {
System.out.println("you win! ");
int random1;
public void doRandom() {
Random die1 = new Random();
random1 = die1.nextInt(6) + 1;
System.out.println("random1 = " + random1);
}If I replace the line " r.doRandom(); " with " random1 = die1.nextInt(6) + 1; System.out.println("random1 = " + random1); " the program will check the "if" condition and stops when it finds the number 5. What's wrong with my code?
Thanks for your help.DrLaszloJamf wrote:
{color:#3D2B1F }You have two, unrelated variables that happen to both be named random1.{color}Opps! Must have missed it. Using two unrelated variables with the same name was, unintentional ~ //yea, right (blush). Thanks for pointing it out. :-)
Encephalopathic wrote:
you never change random1 from within the while loop. You think you do, but it's a different random1 that you're changing, a non-static one that is an instance variable.okay~ but does it mean that 'random1' from the method within the while-loop cannot be used for comparison purpose? I tried using a 'return' value from the doRandom method and use that value inside the "if" condition, but it also does not terminate the loop. The only way it's going to work is by using the solution DrLaszlo gave? Is there any other way to do this by using a call method?
Thanks! -
While loop and data acquisition timing worries
Hello everyone,
I apologize in advance if this is a silly question, but I could not find the answer around here.
I have made a VI to record continuously from 64 analog channels at a 5kHz sampling rate. I then stream this data to a tdms file. The data acquisition and write functions are in a while loop.
I the same loop, I have a bunch of other loops, that each run on their own wait timers to help limit the amount of memory they take up. I am now worried that this may somehow affect my data acquisition timing.
If I put a bunch of timed loops within another loop, does the outer loop run at the same pace as the slowest of the inner loops? And could that mess up my sampling rate?
I have attached my VI, in case what I just wrote makes no sense at all.
Thanks for any tips...
Attachments:
Record_M8viaDAQv3.vi 237 KBWell, looking at your code you will only write to your TDMS file one time. You have multiple infinite loops within the main/outer loop. That means that the main loop will only run a single iteration because it cannot complete an iteration until all code within it completes. With at least two infinite loops inside the loop it will never complete. Not too mention the only way to stop your code is to hit the stop/abort button. NOt a very good way to stop your code. As someone once said using the abort to stop your code is like using a tree to stop your car. It will work but not advised.
As Ben mentioned try to understand data flow better. You have unnecessary sequence frames in your code where normal data flow will control the execution sequence.
Mark Yedinak
"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Maybe you are looking for
-
I've just arrived in London with my G4 iPhone an can connect to service. How do I connect?
-
Data transfer into partition table took more time
Scenario: We have a Staging table (consider it as Table A) which is refreshed Every month. Every month table A is truncated and inserted with 6 million records approx. Once the mandatory update done on Table A we have to move the records to main tabl
-
How do I burn only a portion of a song onto a disc?
How do I burn only a portion of a song onto a disc?
-
I can't update or delete iTunes on my Windows 8.1 laptop
Every time iTunes tries to install an update I get an error; "The feature you are trying to us is on a network resource that is unavailable. click OK to try again, or enter an alternate path to a folder containing the installation package 'iTunes64.m
-
hi guys , can any one tell me how can we extract the HR data sourse and how is will come to bw side is there any special extractors apart tables ,views and function module cheers dp