• Yes, you are right about dynamic queries into functions. When I wrote about "the other functions work as well" I said the other functions are inserting information into a table correctly , but I have a function that joins two tables to show a result

    for example:

    COL1 | COL2 |COL3 | COL4 |

    CAR MODEL| Year | Purchase data | color |

    VW Bettle | 2009 | 2009-01-01 | red |

    Ford Ka | 2013 | 2013 -05-16 | silver |

    Based on the function

    CREATE FUNCTION DBO.UF_DADOS (@CODIGO VARCHAR(50))

    RETURNS TABLE

    AS

    RETURN

    SELECT COL1_H, COL2_H, COL3_H, COL4_H, COL5_H, COL6_H, COL7_H, COL8_H, COL9_H, COL10_H

    FROM TB_HEADER

    WHERE CODIGO = @codigo

    UNION ALL

    SELECT COL1_D, COL2_D, COL3_D, COL4_D, COL5_D, COL6_D, COL7_D, COL8_D, COL9_D, COL10_D

    FROM TB_DADOS

    INNER JOIN TB_HEADER ON TB_HEADER.ID_HEADER = TB_DADOS.ID_HEADER

    WHERE CODIGO = @codigo

    I should have a result like a this:

    CAR MODEL| Year | Purchase data | color |

    VW Bettle | 2009 | 2009-01-01 | red |

    Ford Ka | 2013 | 2013 -05-16 | silver |

    Replacing Col1, Col2, Col3 and Col4 for CAR MODEL,Year,Purchase,data and color. Actually I haven't gotten yet.

    Best Regards