sql-server - SQL SP 中未附加 WHERE 子句
问题描述
我正在尝试运行如下的简单查询,以过滤出状态结果。如果活动、非活动或全部。
IF (@Status = ''
OR @Status IS NULL)
BEGIN
SET @Status = 'ALL'
END
DECLARE @strParam AS varchar(max)
SET @strParam = 'Status: ' +
REPLACE(@Status, '''', '')
SET @strSql = 'SELECT [UserName],[FirstName],[LastName],[Email],[IsActive],''' + @strParam + ''' As Param
,''' + @strLink
+ ''' AS CompanyLogo
FROM [gblUserMaster] '
print @strsql
print @Status
IF @Status = 'Active'
BEGIN
SET @strSql = @strSql + ' WHERE IsActive = 1'
print @strsql
END
IF @Status = 'Inactive'
BEGIN
SET @strSql = @strSql + ' WHERE IsActive = 0'
print @strsql
END
SET @strSql = @strSql + ' ORDER BY gblUserMaster.UserName'
print @strsql
EXEC (@strSql)
@Status = 活动我得到了结果,但是 WHERE 子句没有得到附加....打印给我下面的查询
SELECT [UserName],[FirstName],[LastName],[Email],[IsActive],'Status: Active' As Param
,'' AS CompanyLogo
FROM [gblUserMaster] ORDER BY gblUserMaster.UserName
但是没有 WHERE 子句我做错了什么?
解决方案
推荐阅读
- maven - 插件 org.apache.maven.plugins:无法解析依赖项
- email - Domino:将所有入站电子邮件的副本转发到外部电子邮件地址时,原始收件人丢失
- python - 从 C++ 应用程序调用 python 多元线性回归代码
- flutter - 构造继承的小部件时如何设置基类的属性?
- sql - 如何在PostgreSQL中每小时平均记录数
- javascript - 如何使用相同数量的循环数据循环我的 javascript?
- ios - 在 UICollectionView 中选择 FirstIndex
- linux - 如何通过 DBus 获取 PulseAudio 的源优先级
- java - 使用java swing将控制台输出重定向到文本字段和按钮到控制台输入
- reactjs - React-native 未解决,但已安装