just i need to know how are we concatenate select statement if we have more if condition in side the strode procedure.
as a example
ssql = 'select * from pat'
and i have more selection criteria
whet i need to do is
if (@.pct is not null)
begin
ssql = ssql +' , '+ 'where pct_cd = @.pct
end
any idea
thank you
Niranga
Code Snippet
declare @.sql nvarchar(4000),
@.pct numeric(5,4)
set @.sql =N'SELECT fld1, fld2 FROM table'
if @.pct isnotnull
begin
set @.sql = @.sql +' where pct_cd = '+cast(@.pct asnvarchar(20))
end
execsp_executesql @.sql
|||thank you very much daleJ|||No problem Niranga.
If that is a satisfactory solution, please mark it as an answer.
It's working properly and when I'm executing it says Command(s) completed successfully. but now the problem is not gain any output is there a specific way to execute it.|||
Nope.
Just execute sp_executesql.
Make sure your query returns rows when executed without using the stored procedure to invoke it.
sql
No comments:
Post a Comment