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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Statement

Author  Topic 

shers
Starting Member

3 Posts

Posted - 2006-06-17 : 09:01:31
Hi all,

I have three tables from which I need to retrieve information.

This is the generated SQL Script.

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Designation]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Designation]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Availability]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Availability]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[StaffMaster]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[StaffMaster]
GO

CREATE TABLE [dbo].[Designation] (
[Priority] [int] NULL ,
[Designation] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Discipline] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Availability] (
[Empcode] [nvarchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Discipline] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Month_Year] [smalldatetime] NOT NULL ,
[Avail] [int] NOT NULL ,
[AvailDate] [smalldatetime] NULL ,
[Id] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[StaffMaster] (
[EmpCode] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[EmpName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Designation] [nvarchar] (75) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Discipline] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO


The SQL I am using right now is as follows:

"TRANSFORM Max(Availability.Avail) AS MaxOfAvail 
SELECT StaffMaster.EmpCode, StaffMaster.EmpName, StaffMaster.Discipline, StaffMaster.Designation
FROM StaffMaster
LEFT JOIN Availability
ON
StaffMaster.EmpCode = Availability.Empcode
WHERE (StaffMaster.Designation<>'Project Manager'
AND StaffMaster.Designation
NOT LIKE 'Head%' AND StaffMaster.Designation
NOT LIKE '%Manager%')
GROUP BY StaffMaster.Discipline, StaffMaster.EmpCode, StaffMaster.EmpName, StaffMaster.Designation
ORDER BY StaffMaster.Discipline, StaffMaster.Designation,
StaffMaster.EmpName PIVOT Availability.Month_Year"


It gives me the result, but I wish to get it sorted by Priority field of the Designation table. Can this be accomplished?

Thanks



SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-06-17 : 09:31:03
Access queries has their on forum.
But it would be possible to join in Designation table and sort by that.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-19 : 02:11:28
Are you using SQL Server or Access?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

shers
Starting Member

3 Posts

Posted - 2006-06-19 : 02:52:57
I am using Access with VB 6.0.

Thanks
Go to Top of Page

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2006-06-19 : 03:11:23
Access queries has their on forum.
Go to Top of Page
   

- Advertisement -