Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 We use an interface to run our scripts...
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 05/20/2013 :  16:26:35  Show Profile  Reply with Quote

We use an interface to run our scripts at work
and the interface won't allow us to use views or other more advanced techniques.
I am taking data from 3 different tables, no problem. My problem is that I have to get
the department field value that is valid within work_date_f and work_date_t. The department has a
current_department_date_f and current_department_date_t.
Is this possible without using views or other more advanced techniques?
Sometimes a person can work both a day shift and later a night shift, smae date but at different department.


FROM   work_time AS wt, 
       persons AS p, 
       current_department AS cd 
WHERE  wt.type_of_work = 'ZZ' 
       AND wt.work_date BETWEEN '20130101' AND '201305017' 
       AND ( p.id_nr = wt.id_nr 
             AND cd.id_nr = wt.id_nr ) 
       AND wt.work_date_f >= cd.current_department_date_f 
       AND wt.work_date_f <= cd.current_department_date_t 
ORDER  BY wt.work_date_f, 

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 05/20/2013 :  16:48:32  Show Profile  Reply with Quote
Anything that you would normally do using a view can be done without using a view. That said, it is not clear to me the logic you want to use. Can you post some sample data that is representative of your problem along with the corresponding results that you are trying to get?
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 05/21/2013 :  04:52:45  Show Profile  Reply with Quote
form what i understood you need a correlated query which will be used to relate to department table based on date values to get the associated department value. You could link it to main query using APPLY operator.

See examples here

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000