SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Odd WHERE condition in UPDATE statment.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Eagle_f90
Constraint Violating Yak Guru

USA
424 Posts

Posted - 07/12/2013 :  15:12:47  Show Profile  Visit Eagle_f90's Homepage  Reply with Quote
I am looking at some existing code and at the top of the code it creates a temp table using

Create Table #tmpDriverTime
(DriverName 	Varchar(53)
 ,EmployeeNo	Int
 ,WorkDay1	Float
 ,WorkDay2	Float
 ,WorkDay3	Float
 ,WorkDay4	Float
 ,WorkDay5	Float
 ,WorkDay6	Float
 ,WorkDay7	Float
 ,WorkDay8	Float
 ,WorkDay9	Float
 ,Total6Day	Float
 ,Total7Day 	Float
 ,Total8Day 	Float
 ,HrsAvailable	Float
 ,StartDateTime	DateTime Null
 ,EndDateTime	DateTime Null
 ,Status	Int Null
 ,DateWorked	DateTime Null
 ,WorkDay1Status	Int Null
 ,WorkDay2Status	Int Null
 ,WorkDay3Status	Int Null
 ,WorkDay4Status	Int Null
 ,WorkDay5Status	Int Null
 ,WorkDay6Status	Int Null
 ,WorkDay7Status	Int Null
 ,WorkDay8Status	Int Null
 )


but later in the code there is an UPDATE statement with a WHERE condition I can not figure out.

Update 	#tmpDriverTime
Set 	WorkDay7Status 	= @Result
Where 	EmployeeNo 	= @DrvrID
And 	@PreviousIndex 	= 7


I know it is updating the Temp table to set the column WorkDay7Status to the value in the local varable @Result for the EmployeeNo equal to the value in @DrvrId. What I can't figure out is the second condition of @PreviousIndex = 7 part. There is no column of @PreviousIndex and looking at the code @PreviousIndex is a local variable of type INT. So how exactly does this second condition work?

--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 07/12/2013 :  15:55:23  Show Profile  Reply with Quote
If the variable @PreviousIndex is equal to 7 it will do the update (assuming the other parts of the predicate are also true) otherwise it will not.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3706 Posts

Posted - 07/12/2013 :  15:56:18  Show Profile  Reply with Quote
That acts sort of like a switch. For example, if this code was part of a stored procedure and @PreviousIndex was one of the parameters, the caller could control whether the update would happen or not by passing 7 or something other than 7. Perhaps it is designed so the update will be done only if it is the 7th day of the week.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000