populating a tvp from a UDF table

I am trying to create a stored procedure to compare two return investment plans:
I have a UDF that needs to populate the TVP
This select statement will give me a view of the table data i wish to populate the TVP with

SELECT CustID, CustName, NumberofYears,dbo.IntRate(NumberofYears) AS rate, dbo.FinalAmount(PrincipleAmount, NumberOfYears, DepositType) AS FinalAmount
FROM Customers

I could do this with manual insert values but really would like to use a insert from query method if possible


jrb47Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
you can INSERT or UPDATE from a SELECT/JOIN, but it's not clear at all which data has to go where from your explanations so far ...
0
jrb47Author Commented:
I have created a TVP

CREATE TYPE [dbo].[bestScenario] AS TABLE(
    [CustID] [char](4) NULL,
    [CustName] [char](3) NULL,
    [Principal] [float] NULL,
    [NumberOfYears] [int] NULL,
    [DepositType] [char](6) NULL
)
GO

I need to populate it based on this query which pulls data from 2 UDF's
I need to do this via a stored procedure

query is:
SELECT CustID, CustName, NumberofYears,dbo.IntRate(NumberofYears) AS rate, dbo.FinalAmount(PrincipleAmount, NumberOfYears, DepositType) AS FinalAmount
FROM Customers

I found this link but it is rather confusing for me to try and relate this to what i am doing.....
http://www.dotnetspider.com/resources/35675-About-Table-Type-Table-Valued-Parameters.aspx





0
Guy Hengel [angelIII / a3]Billing EngineerCommented:

the basic SQL would be like this:
INSERT INTO TVP ( customerid, custname, ... )
SELECT CustID, CustName,  ...
FROM Customers

Open in new window

0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

jrb47Author Commented:
i tried that it does not work

0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>it does not work
not very clear as error description ...
0
jrb47Author Commented:
This query does not populate the table so that the data may be used in the stored procedure that is called during the transaction.
0
dwkorCommented:
Can you try this one?
declare
	@Data [dbo].[bestScenario]
	
insert into @Data([CustID],[CustName],[Principal],[NumberOfYears],[DepositType])
	SELECT CustID, CustName, ... -- what are the correct fields?
	FROM Customers

select * from @Data

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jrb47Author Commented:
thank you - i knew there had to be a way!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.