Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
select @amount=tax_amnt from @tblnm where @trn_col_nm=@trn_No and tax_nm=@taxnm

this is my sql , is it possible to write this in dynmaicsql way?
Posted
Updated 31-Jan-12 1:30am
v2

use "exec" function this way
dec @myamt varchar(20);
exec('
declare @amount decimal(12,3);
set  @amount='+@myamt+'
select @amount=tax_amnt from @tblnm where @trn_col_nm=@trn_No and tax_nm=@taxnm')


Note: it is just a example.
 
Share this answer
 
v3
Comments
Rajesh Anuhya 31-Jan-12 8:23am    
Edited: Code tags added
--RA
Execute a stored procedure or function
[ { EXEC | EXECUTE } ]     { 
      [ @return_status = ]
      { module_name [ ;number ] | @module_name_var } 
        [ [ @parameter = ] { value 
                           | @variable [ OUTPUT ] 
                           | [ DEFAULT ] 
                           }
        ]
      [ ,...n ]
      [ WITH RECOMPILE ]
    }
[;];
Execute a character string
{ EXEC | EXECUTE } 
    ( { @string_variable | [ N ]'tsql_string' } [ + ...n ] )
    [ AS { LOGIN | USER } = ' name ' ]
[;];
Execute a pass-through command against a linked server
{ EXEC | EXECUTE }
    ( { @string_variable | [ N ] 'command_string [ ? ]' } [ + ...n ]
        [ { , { value | @variable [ OUTPUT ] } } [ ...n ] ]
    ) 
    [ AS { LOGIN | USER } = ' name ' ]
    [ AT linked_server_name ]
[;];
 
Share this answer
 
v2
Comments
Rajesh Anuhya 31-Jan-12 8:23am    
Edited: Code tags added
--RA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900