Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
issam
Starting Member
30 Posts |
Posted - 2007-08-25 : 13:04:09
|
| Hi,I have an error for the following statement:-DECLARE @MONTHNO charDECLARE @DB CHAR (8)DECLARE @CR CHAR (8)DECLARE @batchno intDECLARE @ACTIVEYEAR intset @batchno = 5set @ACTIVEYEAR = 2007SET @MONTHNO = 2SET @DB = 'DB_'+CONVERT(NCHAR(2),@MONTHNO)SET @CR = 'CR_'+CONVERT(NCHAR(2),@MONTHNO)exec('update bmaster set ' +@DB+'='+@DB+' mysursor.damt,' +@CR+'='+@CR+' mysursor.camt from bmaster inner join (select transact.year,transact.acctno,' +' sum(transact.camt) as camt,' +' sum(transact.damt) as damt,' +' sum(transact.ccamt) as ccamt,' +' sum(transact.cdamt) as cdamt' +' from transact where transact.batchno='+@batchno+ ' and transact.year='+@ACTIVEYEAR +' group by transact.year,transact.acctno) as mysursor on bmaster.year=mysursor.year and bmaster.acctno=mysursor.acctno')the error as follows:-Msg 102, Level 15, State 1, Line 1Incorrect syntax near 'mysursor'.Msg 156, Level 15, State 1, Line 1Incorrect syntax near the keyword 'as'.thanks for your help. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-08-25 : 16:05:49
|
Replace the EXEC statement with a PRINT statement and you will see the error!+@DB+'='+@DB+'+mysursor.damt,'+@CR+'='+@CR+'+mysursor.camt from bmaster inner join (select transact.year,transact.acctno,'Also, @MONTHNO is only CHAR, which means CHAR(1). E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-27 : 02:05:41
|
| Too much DSQL?www.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|