Avatar of chokka
chokkaFlag for United States of America

asked on 

Deleting the columns for a Stored Procedure

SQL 2008

This Stored Procedure works great. But i need to remodify the storedprocedure by deleting 4 columns in the last  (weight,Id,DrugName,      CreatedDate).

These are the Last 4 Columns. On just removing the column affects stored procedure output. So, i am in a situation to retune the stored procedure by removing the columns !!

CREATE Proc [dbo].[usp_ADAPFilteration]            
(
	 @StartDate DateTime,
	 @EndDate DateTime,
	 @SortCode  nvarchar(4000)                                    
)            
As            
            
Begin            
            
;with cte as (                  
select distinct            
     pat.NameLast as [Last Name],                
     pat.NameFirst as [First Name],            
                
     RIGHT( RTRIM( REPLACE( SSN, CHAR(160), '' ) ), 4 ) as [Last 4 Digit of SSN],            
     convert(varchar, Left(Pat.AdrsZip,5),101) as [ZipCode],                
            
     cty.County,                
     pat.SortCode1 as [340B],                    
               
     case when len(pat.DOB) = 7 then dateadd(d, (cast(RIGHT(pat.DOB,3) as int) -1), cast(LEFT(pat.DOB,4) as    DATE))else null end as [DOB],                    
     PAT.licnbr AS [Client ID],      
     case      
     when CONVERT(varchar, pat.weight)  = '1' then 'Insured'      
     when CONVERT(varchar, pat.weight) = '2' then  'Cash'      
     when CONVERT(varchar, pat.weight)  = '3' then  'ADAP'      
     else '0'      
     end as [Insurance Status],    
                      
     Pln.PlanId,                 
               
     Dr.GenericCode,            
     --Dr.GenericName,            
     Dr.Name as [Drug Name],                
     --stuff(Dr.DrugNDCNbr,case when Dr.DrugNDCType in (50, 56) then 1 when Dr.DrugNDCType in (51, 57) then 6    when Dr.DrugNDCType = 52 then 10     end, 0, '0') as [NDC],                
	 case when Dr.DrugNDCType = 49 then Dr.DrugNDCNbr else stuff(Dr.DrugNDCNbr,case when Dr.DrugNDCType in (50, 56) then 1 when Dr.DrugNDCType in (51, 57) then 6 when Dr.DrugNDCType = 52 then 10 end, 0, '0') end as [NDC],  
	 rx.RxNbr,                  
     case when len(Rx.FillDate) = 7 then dateadd(d, (cast(RIGHT(Rx.FillDate,3) as int) -1), cast(LEFT    (Rx.FillDate,4) as DATE))else null end as [Fill Date],                    
     rx.DispensedQty1 as [Dispensed Qty],                
     rx.Refills,                  
     rx.Daysupp as [Days Supplied],                    
     rx.Totalprice as [Plan Allows],      
         
     CASE WHEN pat.Weight = 2    
     THEN '0.0' ELSE rx.Cashpaid     
     END     
     AS [Copay],    
    
    
     CASE WHEN pat.Weight = 2    
     THEN '0.0' ELSE rx.PaidByPlan1     
     END     
     AS [Net due From Insurance]    
                   
     --rx.Cashpaid as [Copay],                
     --rx.PaidByPlan1 as [Net due From Insurance]      
                   
     ,BP.Price as [340B Price],                
     BP.PacketSize as [340B Packet Size],            
       
     case   
     when CONVERT(float, BP.PacketSize) > 0.0 then  
     CONVERT(float, BP.Price) / CONVERT(float, BP.PacketSize) * CONVERT(float,  rx.DispensedQty1)  
     else 0.00000000  
     End  as      [340B Cost for this Rx],  
         
     CP.[Column 1] as [Cardinal Price],            
     CP.[Column 2] as [Packet Size] ,      
         
 case	
		when pat.weight = 1 then 22      
		when pat.Weight = 2 then  15      
        when pat.Weight = 3 then  22      
        else 0      
        end as [Dispensing Fees],pat.weight    
             
     
     
            
from   patient pat                   
inner join   Rx Rx                    
on    Rx.PatNbrKey = Pat.PatKey              
                  
Left join   plans pln            
on    pln.PlanCodeKey = rx.Plan1Key            
            
inner join   drug dr                    
on    dr.DrugNbrKey = rx.DispensedDrugKey                  
            
left join  [340bprice] BP                 
--on   Left(BP.NDC,11) = stuff(Dr.DrugNDCNbr, case when Dr.DrugNDCType in (50, 56) then 1 when Dr.DrugNDCType in    (51, 57) then 6 when Dr.DrugNDCType = 52 then 10 end, 0, '0')                 
on   Left(BP.NDC,11) = case when Dr.DrugNDCType = 49 then Dr.DrugNDCNbr else stuff(Dr.DrugNDCNbr,case when Dr.DrugNDCType in (50, 56) then 1 when Dr.DrugNDCType in (51, 57) then 6 when Dr.DrugNDCType = 52 then 10 end, 0, '0') end           
           
left join  county cty                
on    cty.Zipcode = convert(varchar, Left(Pat.AdrsZip,5),101)             
                 
Left join  CardinalPrice CP            
--on   Left(CP.[Column 0],11) = stuff(Dr.DrugNDCNbr, case when Dr.DrugNDCType in (50, 56) then 1 when Dr.DrugNDCType in (51, 57) then 6 when Dr.DrugNDCType = 52 then 10 end, 0, '0')            
on   Left(CP.[Column 0],11) = case when Dr.DrugNDCType = 49 then Dr.DrugNDCNbr else stuff(Dr.DrugNDCNbr,case when Dr.DrugNDCType in (50, 56) then 1 when Dr.DrugNDCType in (51, 57) then 6 when Dr.DrugNDCType = 52 then 10 end, 0, '0') end   
            
where  pat.SortCode1 like @SortCode + '%' 
             
-- SC MED            
and rx.Plan1Key <> 49            
 and  rx.Rxstatus <> 16            
  and  rx.Rxstatus <> 18            
  and  rx.Rxstatus <> 20            
and   Rx.FillDate BETWEEN YEAR(@StartDate)*1000 + DATEPART(dy, @StartDate)                
AND   YEAR(@EndDate)*1000 + DATEPART(dy, @EndDate) )
select *
  from cte t1
  left join ADAPFormulary t2 on LEFT(t1.[Drug Name],5) = LEFT(t2.DrugName,5) and t1.weight = 3
 where t2.DrugName is null  
order by t1.[Last Name] Asc         
End



GO

Open in new window

Microsoft SQL Server 2008Microsoft SQL Server 2005

Avatar of undefined
Last Comment
chokka
Avatar of Kent Dyer
Kent Dyer
Flag of United States of America image

If you truly want to remove the columns, look into the use of ALTER to ALTER the construct of the table.

HTH,

Kent
Avatar of chokka
chokka
Flag of United States of America image

ASKER

i truly want to remove in the output .. not on the construct of table
Avatar of veenaravind
veenaravind
Flag of India image

I am not quite sure what you are trying to do here. Well, firstly I don't see the above mentioned columns in the select list, so where comes the point of deleting them?

If you could please explain the problem in more detail, may be with the results, it would help.

Thanks,
Veena
Avatar of chokka
chokka
Flag of United States of America image

ASKER

I am facing the same issue, That is an existing stored procedure. I have to remodify the existing stored procedure.

I don't see, the last 4 columns as Weight,Id,DrugName,Created Date inside the storedprocedure. But i could see pat.weight which is mentioned just before From Syntax.
ASKER CERTIFIED SOLUTION
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of chokka
chokka
Flag of United States of America image

ASKER

Thanks
Microsoft SQL Server 2005
Microsoft SQL Server 2005

Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.

72K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo