日期:2014-05-16 浏览次数:20860 次
/* table name:Clients */ CREATE PROCEDURE [sp_Clients] @sp_sort varchar(20)=NULL, @max_column_name varchar(30)=NULL,/*max字段名*/ @Spcial_field varchar(50)=NULL,/*查找指定的字段*/ @Spcial_field_value varchar(50)=NULL,/*查找指定的字段的值*/ @sp_return int=NULL output, @ClientId int=NULL,/*顾客ID*/ @ClientsName varchar(50)=NULL,/*顾客名称*/ @ClientsDescription varchar(50)=NULL,/*顾客描述*/ @Phones varchar(100)=NULL,/*电话号码*/ @ContactPeople varchar(60)=NULL,/*联系人*/ @MobilePhone varchar(30)=NULL,/*手机*/ @Remark varchar(400)=NULL/*备注*/ AS /*================== insert data ======================*/ if @sp_sort='sp_insert' BEGIN /* todo ...省略*/ END /*================== update data ======================*/ else if @sp_sort='sp_update' BEGIN /* todo ...省略*/ END /*================== get max id ======================*/ /* 如何转成 mysql */ else if @sp_sort='sp_getmaxid' BEGIN declare @sql_max varchar(100); set @sql_max ='SELECT '; set @sql_max=@sql_max+' ISNULL(MAX('+@max_column_name+'),'''') FROM Clients' EXECUTE (@sql_max); END /*================== judge the record is exist or not ======================*/ /* 如何转成 mysql */ else if @sp_sort='sp_exists' BEGIN SELECT @sp_return = count(1) FROM Clients WHERE [ClientId]=@ClientId IF @sp_return <> 0 BEGIN set @sp_return=1 END RETURN @sp_return END /*============== judge the special record is exist or not ==================*/ /* 如何转成 mysql */ else if @sp_sort='sp_exists_special' BEGIN declare @sql_field varchar(200); set @sql_field=N'SELECT @sp_return = count(1) FROM Clients WHERE ' + @Spcial_field + ' = ''' + @Spcial_field_value+'''' EXEC sp_executesql @sql_field,N'@sp_return int output',@sp_return output END /*================== get model (a record) ======================*/ else if @sp_sort='sp_getmodel' BEGIN /* todo ...省略*/ END GO