SQL 语句带查询参数问题
本帖最后由 jerry_lian_an 于 2012-10-23 14:59:11 编辑
ALTER procedure [dbo].[sp_DFEFORMT214_getICMApprover]
(
@strCondition as nvarchar(1000)=''
)
AS
DECLARE @strSql NVARCHAR(4000)
SELECT ORG,MODEL,CAT,ROLE,DISPLAY_NAME,SERIAL FROM DFEFORMT214_ICM_APPROVER A,AM_EMPLOYEE B
WHERE A.APPROVER=B.EMP_ID +@strConditionorder by org,model,cat
这里的@strCondition 是类似于AND A.ORG='XX'的查询条件语句,从页面传过来的参数,我应该怎么写啊?
------解决方案--------------------exec('SELECT ORG,MODEL,CAT,ROLE,DISPLAY_NAME,SERIAL FROM DFEFORMT214_ICM_APPROVER A,AM_EMPLOYEE B
WHERE A.APPROVER=B.EMP_ID '+@strCondition+' order by org,model,cat')
------解决方案--------------------ALTER procedure [dbo].[sp_DFEFORMT214_getICMApprover]
(
@strCondition as nvarchar(1000)=''
)
AS
DECLARE @strSql NVARCHAR(4000)
set @strSql='SELECT ORG,MODEL,CAT,ROLE,DISPLAY_NAME,SERIAL FROM DFEFORMT214_ICM_APPROVER A,AM_EMPLOYEE B
WHERE A.APPROVER=B.EMP_ID '+@strCondition+' order by org,model,cat'
exec(@strSql)