Correlated SQL Help

Capodecina
Permabanned
Joined
31 Dec 2003
Posts
5,172
Location
Barrow-In-Furness
I've set up a correlated SQL query but i'm not entirely sure i've got it right.

The purpose of it is to get all the unapproved hours for a TimeCode where the CodeOwner matches @username.

It gets the unapproved hours for every code rather than the ones for the UserName.

Code:
SELECT ID, TimeCode, Date, Hours, Username, Comments, Approved, 

(SELECT CodeOwner FROM lward.tblCodes WHERE tblCodes.CodeID = tblHours.TimeCode AND CodeOwner = @UserName) as CodeOwner

FROM lward.tblHours

WHERE Approved is NULL
 
CodeOwner and UserName have nothing to do with each other.

The Username in tblHours is used for storing who is logging some hours. CodeOwner is the Owner of a paticular time code.

tblHours
ID, TimeCode, Date, Hours, Username, Comments, Approved

tblCodes
CodeID, CodeName, CodeDescription, CodeOwner, CodeCategory

The only relationship is CodeID and TimeCode, CodeID is the primary key and TimeCode is the foreign.
 
When coding in ASP.net and using TableAdapters JOINS mess up the auto-generated INSERT, UPDATE and DELETE sql commands they are created.

It's a rather annoying procedure you have to go through to get them to work using JOINS.
 
Back
Top Bottom