Write a function results to a view

Answered Write a function results to a view

  • Tuesday, May 01, 2012 4:11 PM
     
     

    Hello,

    I have a view in Foxpro which i re wrote as a funcion in SQL because one cannot declare variables in an SQL view. But the problemis when one is selecting from the new function you have to say

    From dbo.function_name(@par1,@par2...@par4000)

    the problem is

    1) that i have to write that in for everysingle query so if i have 500 queries and i changed a parameter i will have to change all 500 queries

    So i was wondering if i could somehow insert the results of the function into a view or table so if there are any changes i just make it in one place rather than everywhere that i call that function

All Replies

  • Tuesday, May 01, 2012 4:16 PM
    Moderator
     
     

    If you always use the same values for parameters, you can do

    create myView as 

    select * from dbo.Function_Name('Static Value1', 'Static Value2', etc.)

    --------------

    If you need to use different values for parameters, there is no simpler way than use a function.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


  • Tuesday, May 01, 2012 4:32 PM
     
     

    ok well its not the same per say...but i inalized the values with defaults but different values can be passed in from a form.

    If not values are passed in the query runs with the default, can that qualify for a view?

  • Tuesday, May 01, 2012 4:39 PM
    Moderator
     
     
    View can not use a variable, so your options are regular query (common portion can be a view) or a function.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

  • Tuesday, May 01, 2012 4:44 PM
     
     

    Well i guess Thats one place that foxpro beats SQL? cause in foxpro i could select from the view and if i had to make a parameter change that query knew nothing about it, but in this if i have to change a parameter i willl need to fix it in all the queries

  • Tuesday, May 01, 2012 5:48 PM
    Moderator
     
     Answered
    In FoxPro view can accept parameters, in SQL Server it can not - that's what function is about or stored procedure.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    • Marked As Answer by KJian_ Thursday, May 10, 2012 6:12 AM
    •