Below is the bare bones of the Sproc I'm working with. Not only is there some nasty string parsing in there but the declared parameters are not helping the speed side of things either.
Can this be split in two? Say a UDF or calling Sproc that will pass the name, strength and pack parameters to the parse and union sproc?
I've got a stinking cold and I can't concentrate so any help would be great guy's!
CREATE PROCEDURE spProcessDrug
@DID varchar(255)
AS
declare @Name varchar(255),
@Strength varchar(50),
@Pack varchar(50)
SELECT @Name = BrandNameParse, @Strength = Strength_Value, @Pack = PckSize_Qty
FROM CT_Parsed
WHERE (DID = @DID)
SELECT DISTINCT RTRIM(DrugDescription) + ' ' + ReorderPackSize AS Detail
FROM ACTDataTable
WHERE (DrugDescription LIKE @Name + '%' AND DrugDescription LIKE '%' + @Strength + N'%' AND ReorderPackSize = @Pack)
UNION
SELECT drug_name + ' ' + drug_strength + ' ' + drug_form + ' ' + drug_packsize AS Detail
FROM TDS
GROUP BY drug_name, drug_strength, drug_form, drug_packsize
HAVING (drug_name LIKE @Name + '%' AND drug_strength LIKE @Strength + '%' AND drug_packsize LIKE @Pack + '%' )
GO
Can this be split in two? Say a UDF or calling Sproc that will pass the name, strength and pack parameters to the parse and union sproc?
I've got a stinking cold and I can't concentrate so any help would be great guy's!
CREATE PROCEDURE spProcessDrug
@DID varchar(255)
AS
declare @Name varchar(255),
@Strength varchar(50),
@Pack varchar(50)
SELECT @Name = BrandNameParse, @Strength = Strength_Value, @Pack = PckSize_Qty
FROM CT_Parsed
WHERE (DID = @DID)
SELECT DISTINCT RTRIM(DrugDescription) + ' ' + ReorderPackSize AS Detail
FROM ACTDataTable
WHERE (DrugDescription LIKE @Name + '%' AND DrugDescription LIKE '%' + @Strength + N'%' AND ReorderPackSize = @Pack)
UNION
SELECT drug_name + ' ' + drug_strength + ' ' + drug_form + ' ' + drug_packsize AS Detail
FROM TDS
GROUP BY drug_name, drug_strength, drug_form, drug_packsize
HAVING (drug_name LIKE @Name + '%' AND drug_strength LIKE @Strength + '%' AND drug_packsize LIKE @Pack + '%' )
GO