-1
while ( select AVG(Rate)+2 From HumanResources.EmployeePayHistory) <20
begin
update HumanResources.EmployeePayHistory
set rate=rate+2
From HumanResources.EmployeePayHistory
if(select MAX(Rate)+2 From HumanResources.EmployeePayHistory)>127
break
else
continue
end

I have Execueted this query but I am Not able to know what is this query working ? what is the use of this query ?? it will be running update for more than 20 and less than 127 OR What ??
I am Totally Confused...!!

5
Contributors
6
Replies
28
Views
4 Years
Discussion Span
Last Post by akkbkht
1

I have Execueted this query but I am Not able to know what is this query working ? what is the use of this query ??

You post a question about a query on your server and it works and you are asking someone to explain to you how this query works on your server that has your data?

I assume that you didn't write this query if you did you wouldn't post a question regarding about it.

I think you need to read how to read SQL query.

I mean this your database (noone has access nor have the same data so it's bit hard to understand what is less 127).

So you need to learn how to run query on the server.

1

Like LastMitch pointed out, we have no idea what this data is in this table or how it is being used with whatever application is using it, so we really can't tell you exactly what the query is going to do beyond the obvious stuff.

In short though, it appears to be a query that updates the Rate column in HumanResources.EmployeePayHistory and add 2 to the value while the value of Rate is greater than 20 and no greater than 127.

Any information beyond that would require someone to know exactly what this data actually is. I also, wouldn't be executing any query if I wasn't exactly sure how it was going to affect my data in the database.

Edited by pixelsoul

0

if(select MAX(Rate)+2 From HumanResources.EmployeePayHistory)>127
break
else
continue

@pixelsoul- one error in your explaination as per i think(i am not sure as the query is max so it will return max of all data or max of data iterated).It will break out of loop if it is greater than 127.So further updation for rate once it is greter than 127.Else continue in while loop until rate is greater than 20.

1

i am not sure as the query is max so it will return max of all data or max of data iterated

Yeah, I wasn't quite sure what to make of that MAX(Rate)+2 either, and I asked myself the same thing. I am "assuming" it is the iterated value as I can't see it making much sense on getting the max of all the values.

Edited by pixelsoul

0

Thank You pixelsoul and IIM ... Now i know how to run the query and what was that in which i was getting confused . Both of You Explained very Well .

Lastmitch i know how to run the query but the query above was above was example given in my book under the topic "While Loop" and I was Not getting it.

Thank YOu all

0

Himanshu.
I think you are making mistake in your range.
When rate is <20,
Increment untill it reaches >127.Right?
But what will happen when rate will = or > then 20?
I tthink you range should be >20 and < 127...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.