Link to home
Start Free TrialLog in
Avatar of James Murrell
James MurrellFlag for United Kingdom of Great Britain and Northern Ireland

asked on

how to rewrite sql query

I have below query but in moving to sql 2008 this code will not run, and i a ashamed to admit i don't understand

the main bit in a join (unsure)

 and sa.mystaff_id *= sb.mystaff_id
select sa.mystaff_id,ad.avail_date,sa.time_from,sa.lenght, vs.fname,vs.sname,vs.mobile,vl.tel1,sb.datetime_id,
 (select time_from from order_reqt where reqt_id = sb.reqt_id) as datetime_time_from,
 (select lenght from order_reqt where reqt_id = sb.reqt_id) as datetime_lenght,
 (select description from order_reqt r,product p where r.reqt_id = sb.reqt_id and r.product_id = p.product_id) as datetime_product,
 (select (vc.fname + ' ' + vc.sname) from order_reqt r,main_order mo,vclient vc where r.reqt_id = sb.reqt_id and r.order_id = mo.order_id and mo.client_id = vc.client_id) as client_name
 from mystaff_avail sa, avail_dates ad, vmystaff vs, mystaff_booking sb, vaddress vl
 where ad.avail_id = sa.avail_id
 and vs.mystaff_id = sa.mystaff_id
 and vl.address_id = vs.address_id
 and sa.mystaff_id *= sb.mystaff_id
 and sb.datetime_id in (select datetime_id from datetime_plan where datetime_from between ad.datetime_from and ad.datetime_to)
and ad.avail_date_id not in 
(select ad1.avail_date_id from avail_dates ad1, mystaff_break sb where 
sb.mystaff_id = sa.mystaff_id
and ad1.avail_date_id = ad.avail_date_id
and dateadd(mi,sa.time_from,ad1.avail_date) < sb.datetime_to
 and dateadd(mi,sa.time_from+sa.lenght,ad1.avail_date) >= sb.datetime_from)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of James Murrell

ASKER

Ah that explains it =  *= is old syntax for left outer join, will check back v soon....
Thanks only 20 other scripts to go