Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 8th, 2005, 06:17 AM
neilault neilault is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 1 neilault User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 0
Question Professional SP Writer Needed! :)

OK here goes... I've just started work on a project previously created by someone else and i'm having a knightmare getting my head around it!

I have a SQL 2000 database and particularly this SP which I am currently working on:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER Procedure psel_BSListOfServicesDue
(
@DepotID int,
@DateFrom datetime,
@DateTo Datetime
)
AS

SET NOCOUNT ON
SELECT DISTINCT
ACAccountID,
DADeliveryAddressID,
AccountNum = CASE WHEN DADeliveryAddressID Is Null THEN ACAccountNum ELSE DADeliveryAccountNum END,
CustomerName = CASE WHEN DADeliveryAddressID Is Null THEN dbo.fsel_CustomerName(ACCompanyName, ACTitle, ACFirstName, '', ACSurname, ACCACategoryID)
ELSE dbo.fsel_CustomerName(DACompanyName, DATitle, DAFirstName, '', DASurname, ACCACategoryID) END,
PostCode = CASE WHEN DADeliveryAddressID Is Null THEN ACPostCode ELSE DAPostCode END,
AIEAccountInstalledEquipmentID,
InstalledEquipment = IEMake + ' ' + IEModel,
MPLastServiceDate,
MPNextServiceDate,
MPMaintenancePlanID
FROM tblAccountDetails
INNER JOIN tblMaintenancePlans ON ACAccountID = MPACAccountID
LEFT OUTER JOIN tblDeliveryAddresses ON MPDADeliveryAddressID = DADeliveryAddressID
LEFT OUTER JOIN tblAccountInstalledEquipment ON MPMaintenancePlanID = AIEMPMaintenancePlanID
LEFT OUTER JOIN tblInstalledEquipment ON AIEIEInstalledEquipmentID = IEInstalledEquipmentID
WHERE ACBoilerServiceDepotID = @DepotID
AND MPJHJobID Is Null
AND MPPlanTerminationDate Is Null
AND ((MPNextServiceDate >= @DateFrom AND MPNextServiceDate <= @DateTo)
OR @DateFrom Is Null)

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

Now this works fine but I need to also get another value which is the enginner that last worked on the service. At the moment within tblMaintenancePlans I have a field called MPPreviousJHJobID which holds a job reference number for the previous service. This can be linked to tblBSWorksheets to a field called WSJHJobID, but we need the TOP one as there is a 1 to many relationship. From there we need a field located in tblBSWorksheets called WSWorkSheetID and this links to a field called CLWSWorkSheetID loctaed in table tblBSCalendar. From here we can then get field CLEngineerEMEmployeeID which then links to the field EMEmployeeID within tblEmployees. From that table we then want EMName to be returned as part of the SP!!!

Hope this is clear as i'm not fully understanding it myself! Hope someone can help!?!

Many thanks.

Reply With Quote
  #2  
Old November 18th, 2005, 09:03 AM
webchetan webchetan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: USA
Posts: 1 webchetan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 3 sec
Reputation Power: 0
Send a message via ICQ to webchetan
Wink Make it simpler

Hi - Well writing a SP is ok, no problems with that, but your explaination is not too clear, and its difficult to understand for a lay man.

To make it simpler instead of using actual name of the tables, replace them with a simpler names and variables such as Table1, Table 2, EmpID, EmpName etc...and so on, depending on your fields in the database, that way I am sure someone will reply as it would be easier to understand.

Khidki Support

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Professional SP Writer Needed! :)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT