1: 2: 3:
declare @sql varchar(5000) set @sql='select sum(CR_APP_AMT) from openquery(TEST, ''SELECT * from laf9.dpaymts where GL_DATE between '''''+ convert(varchar(10),@begindate,101) +''''' and '''''+ convert(varchar(10),@enddate,101) +''''''')' exec(@sql)