Santosh kumar Pithani Ответов: 1

Как выполнить @sqlcondition как динамический в этой ситуации?


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


Что я уже пробовал:

@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.

Спасибо Неосторожность

1 Ответов

Рейтинг:
2

Thava Rajan

Вы можете использовать sp_executesql
sp_executesql (Transact-SQL) | Microsoft Docs[^]


Santosh kumar Pithani

Привет, Раджан, дай мне знать, как ты решишь мою проблему?