Jimmy_inc
asked on
Summarizing Previous - Next - SQL Server Pt2
Hi,
I have the following:
CREATE TABLE [dbo].[EETest](
[Rank] [int] NULL,
[EmployeeID] [int] NULL,
[Category] [nvarchar](15) NOT NULL
)
--
INSERT INTO dbo.EETest VALUES
(1, 1245, 'TestA')
,(2,1245 ,'TestB')
,(3,1245 ,'TestC')
,(4, 1245,'TestA')
,(5,1245 ,'TestB')
,(1,1200 ,'Test3')
,(2, 1200, 'Test4')
,(1, 1321 ,'TestA')
,(1, 1765 ,'TestB');
While this is returning almost what I need :
Select A.EmployeeID,A.Category CategoryFrom, B.Category CategoryTo
From EETest A Join EETest B
on A.Rank = B.Rank-1 and A.EmployeeID = B.EmployeeID
But I need the results of the query to show the following:
pls run for example:
CREATE TABLE [dbo].[EEResultsNeeded](
[EmployeeID] [int] NULL,
[CategoryFrom] [nvarchar](15) NOT NULL,
[CategoryTo] [nvarchar](15) NOT NULL
)
--
INSERT INTO dbo.EEResultsNeeded VALUES
(1245, 'TestA','TestB')
,(1245 ,'TestB','TestC')
,(1245 ,'TestC','TestA')
,(1245,'TestA','TestB')
,(1200 ,'Test3','Test4')
,(1321 ,'TestA','No CategoryTo')
,(1765 ,'TestB','No CategoryTo');
Running SQL Server 2008
I have the following:
CREATE TABLE [dbo].[EETest](
[Rank] [int] NULL,
[EmployeeID] [int] NULL,
[Category] [nvarchar](15) NOT NULL
)
--
INSERT INTO dbo.EETest VALUES
(1, 1245, 'TestA')
,(2,1245 ,'TestB')
,(3,1245 ,'TestC')
,(4, 1245,'TestA')
,(5,1245 ,'TestB')
,(1,1200 ,'Test3')
,(2, 1200, 'Test4')
,(1, 1321 ,'TestA')
,(1, 1765 ,'TestB');
While this is returning almost what I need :
Select A.EmployeeID,A.Category CategoryFrom, B.Category CategoryTo
From EETest A Join EETest B
on A.Rank = B.Rank-1 and A.EmployeeID = B.EmployeeID
But I need the results of the query to show the following:
pls run for example:
CREATE TABLE [dbo].[EEResultsNeeded](
[EmployeeID] [int] NULL,
[CategoryFrom] [nvarchar](15) NOT NULL,
[CategoryTo] [nvarchar](15) NOT NULL
)
--
INSERT INTO dbo.EEResultsNeeded VALUES
(1245, 'TestA','TestB')
,(1245 ,'TestB','TestC')
,(1245 ,'TestC','TestA')
,(1245,'TestA','TestB')
,(1200 ,'Test3','Test4')
,(1321 ,'TestA','No CategoryTo')
,(1765 ,'TestB','No CategoryTo');
Running SQL Server 2008
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.