set @sql = 'declare curCompanyCode cursor for' +
' Select CompanyCode From CWDebit Where IsNull(PayedFlag, 0) = 0 ' +
' And JobNo in (Select JobNo From CWJSMain Where OKFlag = 1 And EndDate between '''+@ETD1+''' and '''+@ETD2+''')'
' Select CompanyCode From CWDebit Where IsNull(PayedFlag, 0) = 0 ' +
' And JobNo in (Select JobNo From CWJSMain Where OKFlag = 1 And EndDate between '''+@ETD1+''' and '''+@ETD2+''')'
@ETD1 nvarchar(10) ='1899-12-30',
@ETD2 nvarchar(10) ='2050-12-31')
as
declare @sql nvarchar(4000)
--定义临时表
Create Table #tmpCompanyCode(
CompanyCode nvarchar(20) null
)
set @sql = 'declare curCompanyCode cursor for' +
' Select CompanyCode From CWDebit Where IsNull(PayedFlag, 0) = 0 ' +
' And JobNo in (Select JobNo From CWJSMain Where OKFlag = 1 And EndDate between '''+@ETD1+''' and '''+@ETD2+''')' execute sp_executesql @Sql
open curCompanyCode