Dynamic T-Sql Queries

Question posted in Computer Software on 09 2009
Rate question difficulty level 0 Votes
let's say you are to write a stored procedure that should decide upon with of its parameters
which table to select from.

for example : if the parameter value is '1', select from the customers table.
                    if the parameter value is '2', select from the orders table.

write a stored procedure that will demonstrate such a select query.
 
 
2 Answers
 

create procedure proc1
@param varchar
as

declare @sqlstr varchar(4000)
set @sqlstr = 'Select * from '

if @param 1
begin
@sqlstr = @sqlstr + 'customers'
end
else @sqlstr = @sqlstr + 'orders'

exec (@sqlstr)
GO


09/07/2009
 
 
amy

I've been looking this one and I can use to my assignment... For now I'm so busy with my Academic Essay and Drama Essay

05/03/2012
 
 
Add an answer*
 
Your name
Email
 
Company: eWave LTD
Location: Glil-Yam , Israel
t-sql sql database

add a question

arrow_blue


Now hiring!
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------