且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在SQL语句中构建动态where条件

更新时间:2022-02-21 21:09:44

使用此:

Declare @Where NVARCHAR(MAX) 

...... Create your Where

DECLARE @Command NVARCHAR(MAX) 
Set @Command = 'Select * From SEM.tblMeasureCatalog AS MC ' ;

If( @Where <> '' )
   Set @Comand = @Command + ' Where ' + @Where

Execute SP_ExecuteSQL  @Command

我对此进行了测试并且有效

I tested this and it Worked