Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
create procedure check
declare @p_condition varchar(50);
declare @p_main varchar(50);
set @p_main='SELECT * FROM MASTER;
set @p_condition=where UPPER(USERNAME)=UPPER(admin);

exec check 



how to execute this . please help
Posted

Hey there,

I think you mean dynamic queries:
Create and Execute Dynamic SQL on T-SQL[^]

Hope it helps

Azee...
 
Share this answer
 
Try this :-
set @UserName as per your need

SQL
Declare @SqlStr Varchar(4000)
Declare @UserName nvarchar(4000)
SET @Sql = ' SELECT  *  from Master where userName = ' + @UserName + ''
Execute(@SqlStr)

--Print @SqlStr
 
Share this answer
 
v2
Try something like this:

SQL
create procedure check
as
begin

declare @p_condition nvarchar(max)
declare @p_main nvarchar(max)

set @p_main='SELECT * FROM MASTER'
set @p_condition=' where UPPER(USERNAME)=UPPER(admin)'

declare @qry nvarchar(max)
set @qry = @p_main + @p_condition

exec (@qry)

end
 
Share this answer
 

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