Reuse a complex query with JOIN

  • Hi

    l'll like to know the best way to call a long and complex query(Stored Procedures ??, table value function??, view??) from many other different SP and do some join with it.

    l tried view but I got theses errors in sql pane :

    Error in list of function arguments: '=' not recognized.

    Error in list of function arguments: 'IS' not recognized.

    Unable to parse query text.

    or create a temp table in my query and use (insert/exec with the complex query) and after I do join ?

    I don't want to use a CTE because it will be called too much.

    thanks

  • dquirion78 (5/16/2014)


    Hi

    l'll like to know the best way to call a long and complex query(Stored Procedures ??, table value function??, view??) from many other different SP and do some join with it.

    l tried view but I got theses errors in sql pane :

    Error in list of function arguments: '=' not recognized.

    Error in list of function arguments: 'IS' not recognized.

    Unable to parse query text.

    or create a temp table in my query and use (insert/exec with the complex query) and after I do join ?

    I don't want to use a CTE because it will be called too much.

    thanks

    There is no catch all "this is the best way". However, you said you want to join to this so that automatically eliminates a stored procedure.

    A view might be a decent option but you have to make sure you don't end up nesting views.

    No clue what the errors mean from the view that you "tried" because we can't see the code used and we have no idea what the tables are like.

    I don't understand you concern about using a CTE when this code will be called frequently. A CTE is not a performance problem by itself. It is just an inline view.

    Perhaps if you can explain what you are trying to do and post some ddl and the possible query we can help you figure out a good way to go about whatever it is you are trying to do.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Hi

    I've conditional expression with IIF function and "=" in and view show me error in sql pane.

    CTE is fine but I want able to use the query with many other query like a I can do with a view but for my query I want to do it show me errors...

    thanks

  • dquirion78 (5/16/2014)


    Hi

    I've conditional expression with IIF function and "=" in and view show me error in sql pane.

    CTE is fine but I want able to use the query with many other query like a I can do with a view but for my query I want to do it show me errors...

    thanks

    Not sure what you mean. You are wanting to use this in SSRS? You do know that you can use a CTE in a view right?

    Still...without some basis of code there is nothing more than a guess anybody can offer.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply