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 March 15th, 2004, 12:18 AM
Brick1235 Brick1235 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 31 Brick1235 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Combining the Statements.

I need some help on combining these SQL statements.

Any one know how to please tell me ok.

Results wanted:

SELECT [DRAWING PROJECT].JOBNO,
[DRAWING PROJECT].JOBDES,
COUNT([DRAWING DETAILS].DWGNO) AS [TotalDwgno],
AVG(ViewR1aa.TSPERCENT) AS [Averagepercent]
FROM [DRAWING DETAILS] INNER JOIN
[DRAWING PROJECT] ON
[DRAWING DETAILS].JOBNO = [DRAWING PROJECT].JOBNO INNER
JOIN
ViewR1aa ON
[DRAWING DETAILS].DWGNO = ViewR1aa.DWGNO
GROUP BY [DRAWING PROJECT].JOBNO,
[DRAWING PROJECT].JOBDES

ViewR1aa:

SELECT DISTINCT
dbo.ViewR1a.DWGNO, dbo.ViewR1a.maxdate,
dbo.TIMESHEET.TSPERCENT,
dbo.TIMESHEET.STAGECODE
FROM dbo.ViewR1a INNER JOIN
dbo.TIMESHEET ON
dbo.ViewR1a.maxdate = dbo.TIMESHEET.[DATE] AND
dbo.ViewR1a.DWGNO = dbo.TIMESHEET.DWGNO
WHERE (NOT (dbo.TIMESHEET.JOBNO LIKE 'EM-G%')) AND
(dbo.TIMESHEET.TSPERCENT IS NOT NULL)

View R1a:

SELECT DISTINCT
TOP 100 PERCENT DWGNO, MAX([DATE])
AS maxdate
FROM dbo.TIMESHEET
WHERE (DWGNO <> '') OR
(DWGNO IS NOT NULL) AND
(JOBNO NOT LIKE 'EM%') AND
(JOBNO IS NOT NULL)
GROUP BY DWGNO
ORDER BY DWGNO)


Instead of having 3 SQL statement is there any other way to reduce it to 2 or 1 statement.

Thank you.

NHK

Reply With Quote
  #2  
Old March 15th, 2004, 01:26 AM
Brick1235 Brick1235 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 31 Brick1235 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
I cant't belive this i am replying my self. Anyway ... This is my progress so far. Still none of them come close to what I wanted with those 3 statements. And yeah I have labeled the solutions using version numbers. U see below:


ver3.1

SELECT [Drawing Details].jobno, COUNT([Drawing Details].dwgno)
AS TotalDraw, AVG([TimeSheetDetail].tspercent)
AS AvgPercent
FROM [Drawing Details], TimeSheetDetail
WHERE (TimeSheetDetail.dwgid = [Drawing Details].dwgid) AND
(DWGNO <> '') OR
(DWGNO IS NOT NULL) AND (JOBNO NOT LIKE 'EM%') AND
(JOBNO IS NOT NULL) AND (NOT (JOBNO LIKE 'EM-G%')) AND
(TimeSheeTDetail.TSPERCENT IS NOT NULL)
GROUP BY [Drawing Details].jobno
ORDER BY jobno


Ver3.0

SELECT [Drawing Details].jobno, COUNT([Drawing Details].dwgno)
FROM [Drawing Details]
WHERE EXISTS
(SELECT DISTINCT
TOP 100 PERCENT DWGNO, MAX([DrawnDate])
AS maxdate, TimesheetDetail.tspercent,
timesheetdetail.stagecode
FROM [Drawing Details] INNER JOIN
[TimeSheetDetail] ON
[Drawing Details].Dwgid = [TimeSheetDetail].Dwgid
WHERE (DWGNO <> '') OR
(DWGNO IS NOT NULL) AND
(JOBNO NOT LIKE 'EM%') AND (JOBNO IS NOT NULL)
AND (NOT (JOBNO LIKE 'EM-G%')) AND
(dbo.TIMESHEETDetail.TSPERCENT IS NOT NULL)
GROUP BY dwgno, Timesheetdetail.tspercent,
Timesheetdetail.stagecode)
GROUP BY [Drawing Details].jobno
ORDER BY jobno

Reply With Quote
  #3  
Old March 15th, 2004, 01:39 AM
Brick1235 Brick1235 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 31 Brick1235 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
I did it!!! I think I did it...

can someone tell me I did it or not? Is this the correct answer?

ver 3.2

SELECT [Drawing Details].jobno, COUNT([Drawing Details].dwgno)
AS TotalDraw, AVG(TimeSheetDetail.tspercent)
FROM [Drawing Details] LEFT JOIN
TimeSheetDetail ON
TimeSheetDetail.dwgid = [Drawing Details].dwgid
WHERE (DWGNO <> '') AND (DWGNO IS NOT NULL) AND
(JOBNO NOT LIKE 'EM%') AND (JOBNO IS NOT NULL) AND
(TimeSheeTDetail.TSPERCENT IS NOT NULL)
GROUP BY [Drawing Details].jobno
ORDER BY jobno


NHK

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Combining the Statements.


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 4 hosted by Hostway
Stay green...Green IT