cafenerogal
Technical User
I'm not a complete newbie to SQL, but I've reached the limit of what I can do with the query I'm working on.
What I need to do is bring back the rows of data where one of the 12 fields I'm checking contain the codes I'm looking for.
Here's how I've declared my variable (this is cut down):
The SELECT includes all the fields that may contain the above codes, with the relevant conditions. The problems is it's not returning any data at all. The rest goes something along the lines of (again this is a cut down version):
Can someone do the honours and let me know where I'm going wrong?
Many thanks
What I need to do is bring back the rows of data where one of the 12 fields I'm checking contain the codes I'm looking for.
Here's how I've declared my variable (this is cut down):
Code:
DECLARE @OPPROCS AS VARCHAR(500)
SET @OPPROCS = ''P273','Q554','Q181','Q188','Q189','H251','H258','H259',
'H281','H288''
The SELECT includes all the fields that may contain the above codes, with the relevant conditions. The problems is it's not returning any data at all. The rest goes something along the lines of (again this is a cut down version):
Code:
SELECT OP.Primary_Procedure_Code,
OP.Procedure_Code_2,
Count(OP.HIS_Identity)
FROM dbo.vw_OP_ALL_Commissioning_0708 as OP
left outer join ReferenceTables..tbl_Refs_OPCS4_L4 as OPCS
on OP.Primary_Procedure_Code = OPCS.Code collate database_default
WHERE
OP.his_activitymonth between '200704' and '200803' and
OP.HIS_PBC_Practice_PCT_Code like 'XYZ%' and
OP.attendance_status in (5, 6) and
OP.Administrative_Category = 1 and
OP.Provider_Code like 'ABC%' and
(OP.Primary_Procedure_Code in (@OPPROCS) or
OP.Procedure_Code_2 in (@OPPROCS))
GROUP BY
OP.Primary_Procedure_Code
OP.Procedure_Code_2,
Can someone do the honours and let me know where I'm going wrong?
Many thanks