Crystalguru
Technical User
MSSQL 2000
Can I declare a table variable, then use it for another table variable?
Here is my code:
Can I declare a table variable, then use it for another table variable?
Here is my code:
Code:
Declare @Patients Table
(ClientKey numeric(16,0) NULL,
UnitKey numeric(16,0) NULL)
INSERT INTO @Patients
SELECT
PatientVisit.ClientKey as ClientKey
,Unit.Key as UnitKey
FROM Unit
INNER JOIN PatientVisit
ON PatientVisit.UnitKey = Unit.Key
/*********************************
Find Count of Patients by Discharge Date
**********************************/
Declare @Discharge Table
(UnitKey Numeric(16,0) NULL,
Count_Patients Numeric(16,0) NULL)
Insert into @Discharge
SELECT
Unit.Key
,Count(Patients.ClientKey) as Count_Patients
FROM Unit
INNER JOIN @Patients
ON @Patients.UnitKey = Unit.Key
Group by Unit.Key