Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have to execute @sqlcondition parameter as dynamic as well as sometimes its append to other queries please help!
DECLARE @return_value int

EXEC @return_value = [dbo].MyProfile_Duplicate   
  @PageNum = 1,
  @PageSize = 50,
  @BreakDownTypeText = N'List',
  @CapOrderCount = NULL,
  @typeofCaporder = NULL,
  @PivotColname = NULL,
  @TableName = N'data',
  @BreakdownCondition = NULL,
  @Distance = NULL,
  @ZipCode = NULL,
  @SqlCondition =N'''SELECT LastSeen,MSACode, Age ,count (1) as TotalSearchCount FROM tablename  WHERE (year IN (''+(Select top 1 year FROM yeardata where addressno=1246)+''))  
and  1=1 group by LastSeen,MSACode, Age'''

SELECT 'Return Value' = @return_value


What I have tried:

@SqlCondition =N'''SELECT LastSeen,MSACode, Age ,count (1) as TotalSearchCount FROM tablename  WHERE (year IN (''+(Select top 1 year FROM yeardata where addressno=1246)+''))

this query comes as a single string so i want to execute as dynamic under sp.

Thanks Inadvance
Posted
Updated 15-Dec-17 20:54pm
v2

1 solution

You can use the sp_executesql
sp_executesql (Transact-SQL) | Microsoft Docs[^]
 
Share this answer
 
Comments
Santosh kumar Pithani 16-Dec-17 3:40am    
Hello Rajan, let me know how you solve my issue?

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