IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[testgolang2]') AND type = 'P')
DROP PROCEDURE [dbo].[testgolang2]
GO
CREATE proc testgolang2
@cmpid int,
@bizid int,
@conidtion varchar(1000),
@isview int
as
begin 
declare @sql varchar(max) 
declare @tbname varchar(50)
declare @dbname varchar(50)
declare @fkey   varchar(50) 
exec sys_sql_getTableNamePk @cmpid,'biz',@bizid,0,@tbname output,@fkey output ,@dbname output 

if @isview = 1 
begin
set @sql = '
   select convert(varchar(255),orda_ordafid)+'':''+convert(varchar(255),orda_cuid) as fldkey,orda_ordafid as aid,orda_cuid as cuid from '+@dbname+@tbname +'_authority with(nolock) where orda_cuid>0 
'
end else
begin
set @sql = '
   select convert(varchar(255),orda_ordafid)+'':''+convert(varchar(255),orda_cuid) +'':''+convert(varchar(255),orda_type) as fldkey,orda_ordafid as aid,orda_cuid as cuid,orda_type as pptype from '+@dbname+@tbname +'_authority_control with(nolock) where orda_cuid>0  
'
end

if @conidtion> '' select @sql = @sql+' and ' + @conidtion

  
print @sql 
execute(@sql)
--select GETDATE()


end