Hi,
I have a cursor inside a stored procedure which basically gets the date from a table and runs the query for that dates and inserts into another table.Below is my procedure
ALTER procedure [Staging].[pODS_Ins_tODS_GetStoreTraffic]
AS
BEGIN
BEGIN TRANSACTION
Declare @vDate Date
Declare @vQuery nvarchar(200)
Declare vCur Cursor local
for
Select Date
From ODS.Staging.tODS_StoreTrafficRunDates
Open vCur
Fetch next
from vCur into @vDate
While @@FETCH_STATUS=0
Begin
Set @vQuery= 'SELECT
QtyTraffic
FROM OPENQUERY([ssc2008],
''select * from TMS_Live.dbo.fnExportTraffic('''''+CONVERT(VARCHAR(10),@vDate,110)+''''','''''+CONVERT(VARCHAR(10),@vDate,110)+''''',3)'')'
Insert Into ODS.Staging.tODS_StoreTrafficStg
Exec sp_executesql @stmt = @vQuery
Fetch next from vCur into @vDate
End
close vCur
deallocate vCur
COMMIT TRANSACTION
END
And here is the format of date in my first table '2013-11-24 00:00:00.000'.
If i run this procedure i receive the following error:-
" Unclosed quotation mark after the character string 'select * from TMS_Live.dbo.fnExportTraffic('11-'. "
I know this error is from the place where i am selecting the date from cursor, everything looks good to me, i cannot figure out where i am going wrong.Can someone please help me with this?
Thanks
I have a cursor inside a stored procedure which basically gets the date from a table and runs the query for that dates and inserts into another table.Below is my procedure
ALTER procedure [Staging].[pODS_Ins_tODS_GetStoreTraffic]
AS
BEGIN
BEGIN TRANSACTION
Declare @vDate Date
Declare @vQuery nvarchar(200)
Declare vCur Cursor local
for
Select Date
From ODS.Staging.tODS_StoreTrafficRunDates
Open vCur
Fetch next
from vCur into @vDate
While @@FETCH_STATUS=0
Begin
Set @vQuery= 'SELECT
QtyTraffic
FROM OPENQUERY([ssc2008],
''select * from TMS_Live.dbo.fnExportTraffic('''''+CONVERT(VARCHAR(10),@vDate,110)+''''','''''+CONVERT(VARCHAR(10),@vDate,110)+''''',3)'')'
Insert Into ODS.Staging.tODS_StoreTrafficStg
Exec sp_executesql @stmt = @vQuery
Fetch next from vCur into @vDate
End
close vCur
deallocate vCur
COMMIT TRANSACTION
END
And here is the format of date in my first table '2013-11-24 00:00:00.000'.
If i run this procedure i receive the following error:-
" Unclosed quotation mark after the character string 'select * from TMS_Live.dbo.fnExportTraffic('11-'. "
I know this error is from the place where i am selecting the date from cursor, everything looks good to me, i cannot figure out where i am going wrong.Can someone please help me with this?
Thanks