I have a StoredProcedure, to which i am passing Table Name as Input Paramter ..
On doing so, i am getting an error ..
Msg 1087, Level 16, State 1, Procedure usp_DrugSummationByGeneric
Code, Line 15
Must declare the table variable "@table".
So, How to pass Table Name as Input Paramter for a StoredProcedure. Since i need to use this Query Syntax for more than one table on multiple scenarios
Create proc usp_DrugSummationByGenericCode
with p as (
Sum(OC.[Dispensed Qty]) as Qty
from @table OC
Group By OC.[Generic Code], OC.NDC,OC.[Drug Name]
select x.[Generic Code], x.NDC, x.[Drug Name], y.Qty from
select p.*, row_number() over (partition by [Generic Code] order by Qty desc) rn from p
select [Generic Code], sum(Qty) Qty from p group by [Generic Code]
on x.[Generic Code]=y.[Generic Code]