![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
CREATE PROCEDURE comptabilisationDYN @colonne varchar(3) '*receives R1, then R2, loop is in vba access* AS DECLARE @SQLStatement varchar(8000) DECLARE @TotalNum4 int DECLARE @TotalNum3 int DECLARE @TotalNum2 int DECLARE @TotalNum1 int SELECT SQLStatement = 'SELECT COUNT(*) FROM dbo.Tbl_Réponses_Étudiants WHERE' + @colonne + '=4 AND YY = @year' EXEC sp_executesql @SQLStatement, N'@TotalNum4 int OUTPUT', @TotalNum4 OUTPUT |
#3
| |||
| |||
|
|
Patrik (patrik.maheux (AT) umontreal (DOT) ca) writes: CREATE PROCEDURE comptabilisationDYN @colonne varchar(3) '*receives R1, then R2, loop is in vba access* AS DECLARE @SQLStatement varchar(8000) DECLARE @TotalNum4 int DECLARE @TotalNum3 int DECLARE @TotalNum2 int DECLARE @TotalNum1 int SELECT SQLStatement = 'SELECT COUNT(*) FROM dbo.Tbl_Réponses_Étudiants WHERE' + @colonne + '=4 AND YY = @year' EXEC sp_executesql @SQLStatement, N'@TotalNum4 int OUTPUT', @TotalNum4 OUTPUT You need: SELECT SQLStatement = 'SELECT @TotalNum4 = COUNT(*) FROM dbo.Tbl_Réponses_Étudiants WHERE' + @colonne + '=4 AND YY = @year' EXEC sp_executesql @SQLStatement, N'@TotalNum4 int OUTPUT', @TotalNum4 OUTPUT You also need to add @year to the parameter list. -- Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Thank You, but i have tried your code before and again and it still doesn't work. I call the procedure and it seems to work but it doesn't write anything in the table. It doesn't recognize the ouput variable in the INSERT line. |
#6
| |||
| |||
|
|
Patrik (patrik.maheux (AT) umontreal (DOT) ca) writes: Thank You, but i have tried your code before and again and it still doesn't work. I call the procedure and it seems to work but it doesn't write anything in the table. It doesn't recognize the ouput variable in the INSERT line. Could you post the exact code you have now. Looking back on your post, I see now that there will be a syntax error from the dynamic SQL. Judging from the code you posted, you should always get a row insered, even if only a NULL value. I assume that "seems to work" does not mean that you don't get any error messages. But maybe you should try running the procedure from Query Analyzer, in case you have poor error handling in your Access code. -- Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp |
#7
| |||
| |||
|
|
Patrik (patrik.maheux (AT) umontreal (DOT) ca) writes: Thank You, but i have tried your code before and again and it still doesn't work. I call the procedure and it seems to work but it doesn't write anything in the table. It doesn't recognize the ouput variable in the INSERT line. Could you post the exact code you have now. Looking back on your post, I see now that there will be a syntax error from the dynamic SQL. Judging from the code you posted, you should always get a row insered, even if only a NULL value. I assume that "seems to work" does not mean that you don't get any error messages. But maybe you should try running the procedure from Query Analyzer, in case you have poor error handling in your Access code. -- Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp |
![]() |
| Thread Tools | |
| Display Modes | |
| |