mammouth
asked on
EXEC DECLARE CURSOR with variable as tablename
Following code is not working and return A cursor with the name 'Cur' does not exist.
But if i replace EXEC() by PRINT and run the printed line manually is working. What can i do?
EXEC('DECLARE Cur CURSOR LOCAL FORWARD_ONLY READ_ONLY FOR SELECT DISTINCT(UI.FK_UserId), UI.DateInscrit, SM.DateEncaissement FROM Stats..UserNfo UI, SalesMembership SM, Stats_Panier_Moyen_'+@sPay s+'_Cumul SPMCC WHERE UI.FK_UserId=SM.FK_UserId AND UI.FK_UserId=SPMCC.FK_User Id AND SM.Annule=0 AND SM.MontantEncaissement>0 AND SM.DateEncaissement<='''+@ DateArretS uivi+''' ORDER BY SM.DateEncaissement')
But if i replace EXEC() by PRINT and run the printed line manually is working. What can i do?
EXEC('DECLARE Cur CURSOR LOCAL FORWARD_ONLY READ_ONLY FOR SELECT DISTINCT(UI.FK_UserId), UI.DateInscrit, SM.DateEncaissement FROM Stats..UserNfo UI, SalesMembership SM, Stats_Panier_Moyen_'+@sPay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops almost an accidental sear word idue to typo replace twhat with what
:( my fingers arent working properly today... Ill blame the keyboard :)