Click here to Skip to main content
14,664,097 members
Rate this:
Please Sign up or sign in to 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

Rate this:
Please Sign up or sign in to vote.

Solution 1

You can use the sp_executesql
sp_executesql (Transact-SQL) | Microsoft Docs[^]
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100