SQL存储过程传入字段名查询.

根据字段名和对应的值查询.
(正确代码):目前发现,需要"分组,排序"等才能解决,如"order by","group by"等.
SQL代码:
  
ALTER PROCEDURE USP_QueryT_AddressBookByField
@FieldName nvarchar(20), --字段名.
@FieldVal nvarchar(50) --字段对应的值.
AS
SET NOCOUNT ON
declare @query nvarchar(max)
set @query = 'select [FId] as [编号],[FName] as [姓名],[FSex] as [性别],[FPhone] as [电话号码],[Fqq] as [QQ],
[FWordPhone] as [国际电话号码],[FEMail] as [EMail],[FHandSet] as [手机号] from
[T_AddressBook] where '+@FieldName+'='''+@FieldVal+''' order by [FId]'
exec(@query)

Note:

--EXEC SP_EXECUTESQL @sql 会报错:
--Procedure or function 'USP_QueryT_AddressBookByField' --expects parameter '@FieldVal', which was not supplied.
上一篇:icons 在线网站


下一篇:jQuery(三) javascript跨域问题(JSONP解决)