declare @tags1 varchar(max)
declare @blockcount int
declare @blockstring varchar(max)
set @tags1='%Gifts%' Or CategoryTag Like'%Packaging%'
set @blockstring= 'SELECT @blogcount=count(*) FROM M_PHBLogs where CategoryTag LIKE '+ @tags1 +' AND ContentType=1 '
exec (@blockstring)
ich sp_executesql
das Ergebnis von exec (@blockstring) in eine andere Variable wieWie Wert der Variablen auf 'exec' in SQL mit
@blockcount=exec(@blockstring)
if(@blockcount!=0)
BEGIN
//something
END
Mögliche Duplikat von [Wie ein exec Ergebnis einer SQL-Variablen zuweisen? ] (http://stackoverflow.com/questions/2245691/how-to-assign-an-exec-result-to-a-sql-variable) – HoneyBadger
Mögliches Duplikat von [Wie bekomme ich sp \ _executesql result in eine Variable? ] (http://stackoverflow.com/questions/803211/how-to-get-sp-executesql-result-into-a-variable) –