The Group by clause will combine any records where your fields are
duplicated across the fields shown. So that might account for you having
less records in the table you are creating - hard to say since I don't know
your data and don't know if you have duplicates.
The data mismatch error would probably be caused by the ON clause since I
don't see anything else that could generate the error. Are the two
fields -
[data for sg2 v2].[main specialty] and [spec look up].code
of the same data type? Are they BOTH number fields or is one of them a text
field that contains number characters and the other a number field?
SELECT [data for sg2 v2].activity, [data for sg2 v2].[main specialty]
, [spec look up].specialty, [data for sg2 v2].[treatment specialty]
, [data for sg2 v2].[hrg code], [data for sg2 v2].[primary diagnosis]
, [data for sg2 v2].[primary procedure], [data for sg2 v2].[secondary
procedure]
, [data for sg2 v2].PCT, [data for sg2 v2].[PCT Name]
, [data for sg2 v2].[PCT Name]
, [data for sg2 v2].incode, [data for sg2 v2].sex, [data for sg2 v2].age
, [data for sg2 v2].volume, [data for sg2 v2].[Spell ALoS]
INTO [data for sg2 v3]
FROM [data for sg2 v2] LEFT JOIN [spec look up]
ON [data for sg2 v2].[main specialty] = [spec look up].code
GROUP BY [data for sg2 v2].activity, [data for sg2 v2].[main specialty]
, [spec look up].specialty, [data for sg2 v2].[treatment specialty]
, [data for sg2 v2].[hrg code], [data for sg2 v2].[primary diagnosis]
, [data for sg2 v2].[primary procedure], [data for sg2 v2].[secondary
procedure]
, [data for sg2 v2].PCT, [data for sg2 v2].[PCT Name]
, [data for sg2 v2].[PCT Name], [data for sg2 v2].incode
, [data for sg2 v2].sex, [data for sg2 v2].age, [data for sg2 v2].volume
, [data for sg2 v2].[Spell ALoS];
If you wanted to find out if you had duplicates based on the above you could
run this query.
SELECT Count(*) as RecordCount
,[data for sg2 v2].activity, [data for sg2 v2].[main specialty]
, [data for sg2 v2].[treatment specialty]
, [data for sg2 v2].[hrg code], [data for sg2 v2].[primary diagnosis]
, [data for sg2 v2].[primary procedure], [data for sg2 v2].[secondary
procedure]
, [data for sg2 v2].PCT, [data for sg2 v2].[PCT Name]
, [data for sg2 v2].[PCT Name]
, [data for sg2 v2].incode, [data for sg2 v2].sex, [data for sg2 v2].age
, [data for sg2 v2].volume, [data for sg2 v2].[Spell ALoS]
FROM [data for sg2 v2]
GROUP BY [data for sg2 v2].activity
, [data for sg2 v2].[main specialty]
,[data for sg2 v2].[treatment specialty]
, [data for sg2 v2].[hrg code], [data for sg2 v2].[primary diagnosis]
, [data for sg2 v2].[primary procedure], [data for sg2 v2].[secondary
procedure]
, [data for sg2 v2].PCT, [data for sg2 v2].[PCT Name]
, [data for sg2 v2].[PCT Name], [data for sg2 v2].incode
, [data for sg2 v2].sex, [data for sg2 v2].age, [data for sg2 v2].volume
, [data for sg2 v2].[Spell ALoS]
HAVING COUNT(*) > 1
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..