问题描述
1:selectmax(送货部门)from(SELECTTOP100*FROM送货记录ORDERBY送货部门)这条语句怎么错了2:ALTERPROCEDUREp_select_page(@TableNamenvarchar(100),--表名@fieldnamenvarchar(1000)='*',--列名@StrWherenvarchar(500)='1=1',--Where子句@IdentityKeynvarchar(100)='id',--标识列@PageNumint=1,--页号@PageSizeint=10,--页大小@ordervarchar(10)='asc',--排序@operatorint=0)ASDECLARE@sqlNVARCHAR(1000)DECLARE@paramDefineNVARCHAR(1000)DECLARE@TotalRecordCountint--总记录数DECLARE@PageCountint--总页数--数据表中总记录数SET@sql='SELECT@TotalRecordCount=COUNT(*)FROM'+@TableName+'WHERE1=1'IF@StrWhereISNOTNULLAND@StrWhere<>''SET@sql=@sql+'AND'+@StrWhereSET@paramDefine='@TotalRecordCountINTOUTPUT'EXECSP_EXECUTESQL@sql,@paramDefine,@TotalRecordCountOUTPUT--验证页大小IF@PageSize<0SET@PageSize=0IF@PageSize>@TotalRecordCountSET@PageNum=@TotalRecordCount--计算总页数IF@TotalRecordCount%@PageSize=0SET@PageCount=@TotalRecordCount/@PageSizeELSESET@PageCount=@TotalRecordCount/@PageSize+1--验证页号IF@PageNum>@PageCountSET@PageNum=@PageCountIF@PageNum<1SET@PageNum=1IF@operator=0select@PageCountaspagecountELSEBEGINDECLARE@foreRecordCountINTSET@foreRecordCount=(@PageNum-1)*@PageSize+1SET@sql='SELECTTOP'+CAST(@PageSizeasvarchar)+''+@fieldname+'FROM'+@TableName+'WHERE'+@IdentityKeyIF@order='asc'SET@sql=@sql+'>=(SELECTMAX('+@IdentityKey+')FROM(SELECTTOP'ELSESET@sql=@sql+'<=(SELECTMIN('+@IdentityKey+')FROM(SELECTTOP'SET@sql=@sql+CAST(@foreRecordCountasvarchar)+''+@IdentityKey+'FROM'+@TableName+'ORDERBY'+@IdentityKey+''+@order+')ASTempTable)'IF@StrWhereISNOTNULLAND@StrWhere<>''SET@sql=@sql+'AND'+@StrWhereSET@sql=@sql+'ORDERBY'+@IdentityKey+''+@orderSET@paramDefine=N'@PageSizeINT,@foreRecordCountINT'EXECSP_EXECUTESQL@sql,@paramDefine,@PageSize,@foreRecordCountEND在查询分析器中调用时怎么批定WHERE条件,麻烦写亲测试后的语句,我写的是@strWhere='送货部门=D61',提示找不到D61字段,但D61是字段送货部门中的一个值
解决方案
解决方案二:
@strWhere='送货部门='D61'']值要加上引号
解决方案三:
按楼上的做了,也不行哦
解决方案四:
@strWhere='送货部门=''D61''']