Hi,
I have created one table-valued function. And I want to call this function in stored procedure.
How can I achieve this?
I want to select billid and visitid into SP.
Function query is as below:
CREATE FUNCTION funReturnIPDData
(
)
RETURNS TABLE
AS
RETURN
(
-- Add the SELECT statement with parameter references here
with cte_billinfo(bill_id, visit_id, totalbill) as
(
select B.ipdbill_id, B.ipdpatvisit_id, B.ipdbill_grandtotal from Tbl_IPDBillingDetails B, Tbl_IPDPatientVisit V
where B.ipdpatvisit_id=V.ipdpatvisit_id
),
cte_billselect(billid, visitid)
as
(
select max(bill_id) as billid, visit_id from cte_billinfo c, Tbl_IPDPatientVisit V
group by c.visit_id, V.ipdpatvisit_id, c.totalbill
having c.visit_id=V.ipdpatvisit_id
)
select billid,visitid from cte_billselect
)
GO
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dharmraj ThakurPosted Feb 3, 2018, 1:47 AM
Nitin SontakkePosted Feb 3, 2018, 1:20 AM