• smeet.sinha (1/27/2009)


    Can't we use execute statement in functions?????

    No, you can't.

    My second question is : How can i store a value returned from execute(tsql) in a variable.

    Look up sp_executesql. It allows passing both input and output parameters. There are some good examples in Books Online.

    That said, your example doesn't need dynamic SQL at all. Is the real situation more complex?

    declare @Sal decimal (16,2)

    select @Sal = salary from employee -- which salary are you getting here?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass