Hi Guys,
Here's my query. What I want to do is run this query every week so table PlanFinder.InvalidAwps
will have new records. But when I run the query it gives me this error :
There is already an object named 'InvalidAwps' in the database.
I can't change the table name. It has to remain the same. So how can I run this query every week keeping table name as it is?
Appreciate any help. Thanks Nick
-------------------------------------
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[PlanFinder].[InvalidAwps]')
AND type in (N'U'))
BEGIN
DROP TABLE [PlanFinder].[InvalidAwps]
END
SELECT DISTINCT P.Ndc Ndc, A.Price AwpUnitCost INTO PlanFinder.InvalidAwps
FROM
PlanFinder.PlanFinder.HpmsFormulary P
LEFT JOIN (SELECT Ndc, Price FROM MHSQL01D.Drug.FdbPricing.vNdcPrices
WHERE PriceTypeCode = '01' AND CurrentFlag = 1) A
ON P.Ndc = A.Ndc
WHERE (A.Ndc IS NULL OR A.Price <= 0 OR A.Price IS NULL)
AND p.Ndc IS NOT NULL
----------------------------------------------