This question about the stored procedure is 2 part:
Following is the DDL for the test data which I am working on.
My goal is to build another table with the following columns:
A supervisor is also an employee, his LawsonID is found within the same table too.
My stored procedure till now is:
Now are my questions:
1. What I intend to do is: take data from the 'Test' table one row at a time. I chose to look at the minimum 'LawsonID' and then insert into BuildOrganization table. When I run "Select Min(LawsonID) from Test". It works. It returns 10956. But when I put it in the where clause, it does not return any rows. Why would that be?
2. Taking each row, I want to split the 'Supervisor' column into 'NextManagerFirstName' and 'NextManagerLastName'. Can I split it row by row and then insert into the 'BuildOrganization' table?
I am using SQL Server 2000.
Thanks.
Following is the DDL for the test data which I am working on.
Code:
CREATE TABLE Test (
LawsonID varchar(20) primary key,
FirstName varchar(100),
LastName varchar(100),
Supervisor varchar(100)
)
INSERT INTO Test(LawsonID, FirstName, LastName, Supervisor) Values ('10956',
'Ali','Chowdhury','Pidaparti, Purna')
INSERT INTO Test(LawsonID, FirstName, LastName, Supervisor) Values ('14533',
'Bradley','Rosintoski','Pidaparti, Purna')
INSERT INTO Test(LawsonID, FirstName, LastName, Supervisor) Values ('18778',
'Brian','Emmett','Pidaparti, Purna')
INSERT INTO Test(LawsonID, FirstName, LastName, Supervisor) Values ('21337',
'Sathiya','Rajagopal','Pidaparti, Purna')
INSERT INTO Test(LawsonID, FirstName, LastName, Supervisor) Values ('T2276',
'Aravind','Seshadri','Rajagopal, Sathiya')
INSERT INTO Test(LawsonID, FirstName, LastName, Supervisor) Values ('T2756',
'Polar','Huang','Rajagopal, Sathiya')
INSERT INTO Test(LawsonID, FirstName, LastName, Supervisor) Values ('T951',
'Rishi','Kabra','Rajagopal, Sathiya')
INSERT INTO Test(LawsonID, FirstName, LastName, Supervisor) Values ('T2396',
'Johnson','Abraham','Chowdhury, Ali')
INSERT INTO Test(LawsonID, FirstName, LastName, Supervisor) Values ('T716',
'Kevin','Schmidt','Chowdhury, Ali')
INSERT INTO Test(LawsonID, FirstName, LastName, Supervisor) Values ('24990',
'Purna','Pidaparti','Ileana Rivera')
My goal is to build another table with the following columns:
Code:
LawsonID, FirstName, LastName, Supervisor, SupervisorID, SupervisorFirstName,
SupervisorLastName, NextLevelManagerID, NextLevelManagerFirstName,
NextLevelManagerLastName
A supervisor is also an employee, his LawsonID is found within the same table too.
My stored procedure till now is:
Code:
ALTER Procedure BuildOrganization1
AS
Declare @minLawson varchar
Set @minLawson = (Select min(LawsonID) from Test)
Print '@minLawsonID: ' + @minLawson
--Drop the table and re-build the table from scratch.
If exists(Select * From Information_Schema.Tables Where Table_Name = 'BuildOrganization' AND Table_Type = 'Base Table')
BEGIN
Drop Table [dbo].[BuildOrganization]
END
Create Table BuildOrganization(
LawsonID varchar(100) Primary Key,
FirstName varchar(100),
LastName varchar(100),
DirectManagerLawsonID varchar(100),
DirectManagerFirstName varchar(100),
DirectManagerLastName varchar(100),
NextLevelManagerLawsonID varchar(100),
NextLevelManagerFirstName varchar(100),
NextLevelManagerLastName varchar(100)
)
INSERT INTO BuildOrganization(LawsonID,FirstName,LastName,DirectManagerLawsonID,
DirectManagerFirstName,DirectManagerLastName,NextLevelManagerLawsonID,
NextLevelManagerFirstName,NextLevelManagerLastName)
SELECT LawsonID, FirstName, Lastname, NULL, NULL, NULL, NULL, NULL, NULL
FROM Test
Where LawsonID = @minLawson
--Where LawsonID = '10956'
Execute BuildOrganization1
Now are my questions:
1. What I intend to do is: take data from the 'Test' table one row at a time. I chose to look at the minimum 'LawsonID' and then insert into BuildOrganization table. When I run "Select Min(LawsonID) from Test". It works. It returns 10956. But when I put it in the where clause, it does not return any rows. Why would that be?
2. Taking each row, I want to split the 'Supervisor' column into 'NextManagerFirstName' and 'NextManagerLastName'. Can I split it row by row and then insert into the 'BuildOrganization' table?
I am using SQL Server 2000.
Thanks.