J
Joriz
I have this code in my btnclick event.
Dim cnn As New SqlConnection(Constants.SQLConnectionString)
Dim cmd As New SqlCommand
Dim cmd As New SqlCommand("spAverage", cnn)
cnn.Open()
cmd.CommandType = CommandType.StoredProcedure
Dim prm1 As SqlParameter = cmd.Parameters.Add("@sdate",
txtsdate.Text)
Dim prm2 As SqlParameter = cmd.Parameters.Add("@edate",
txtedate.Text)
cmd.ExecuteNonQuery(CommandBehavior.CloseConnection)
The spAverage does not return any resultset, but it does create a new
table with the all the rows based on the date range parameter that i
passed.
but right after i execute the sp and i check the table that was
created. its empty..altho i know there should be rows in there.
anybody have this problem as well.
Please HELP
here's my sp.
CREATE PROCEDURE spAverage @sdate NVARCHAR(10),@edate NVARCHAR(10)
AS
SET NOCOUNT ON
SET @sdate = CONVERT(NVARCHAR(8),CAST(@sdate AS DATETIME),112)
SET @edate = CONVERT(NVARCHAR(8),CAST(@edate AS DATETIME),112)
IF not object_id('tempdb..#t1') is null
DROP TABLE #t1
SELECT r.qid,svalue1 = AVG(CAST(r.surveyvalue AS DECIMAL)) INTO #T1
FROM groupq g
INNER JOIN questionaires q ON q.groupid = g.groupid
INNER JOIN result r ON r.qid = q.qid
INNER JOIN participant p ON p.participantid=r.participantid
INNER JOIN lkcourse l ON l.courseid= p.levelid
WHERE q.ratetype IN (1,2) and surveyvalue is not null and
surveyvalue <> 0 AND l.grp IN ('G')
AND (CONVERT(NVARCHAR(8),p.EntryDate,112) BETWEEN @sdate AND
@edate)
GROUP BY r.qid
order by r.qid
if not object_id('tempdb..#t2') is null
drop table #t2
select qid2=r.qid,svalue2 = AVG(CAST(r.surveyvalue AS DECIMAL)) INTO
#T2
FROM groupq g
INNER JOIN questionaires q ON q.groupid = g.groupid
INNER JOIN result r ON r.qid = q.qid
INNER JOIN participant p ON p.participantid=r.participantid
INNER JOIN lkcourse l ON l.courseid= p.levelid
WHERE q.ratetype IN (1,2) and surveyvalue is not null and
surveyvalue <> 0 AND l.grp IN ('M')
AND (CONVERT(NVARCHAR(8),p.EntryDate,112) BETWEEN @sdate AND
@edate)
GROUP BY r.qid
order by r.qid
if not object_id('tempdb..#t3') is null
drop table #t3
select qid3=r.qid,svalue3 = AVG(CAST(r.surveyvalue AS DECIMAL)) INTO
#T3
FROM groupq g
INNER JOIN questionaires q ON q.groupid = g.groupid
INNER JOIN result r ON r.qid = q.qid
INNER JOIN participant p ON p.participantid=r.participantid
INNER JOIN lkcourse l ON l.courseid= p.levelid
WHERE q.ratetype IN (1,2) and surveyvalue is not null and
surveyvalue <> 0 AND l.grp IN ('P')
AND (CONVERT(NVARCHAR(8),p.EntryDate,112) BETWEEN @sdate AND
@edate)
GROUP BY r.qid
order by r.qid
if not object_id('tempdb..#t4') is null
drop table #t4
SELECT * INTO #T4 FROM #T1 t1
FULL JOIN #T2 t2 ON t2.qid2 = t1.qid
FULL JOIN #T3 t3 ON t3.qid3 = t1.qid
UPDATE #T4 SET qid=ISNULL(qid2,qid3) WHERE ISNULL(qid,'')=''
if EXISTS(select [name] from sysobjects where [name] = 'tpAverage')
DROP TABLE tpAverage
select tp.topicid,tp.topicdesc,g.qnum,g.groupdesc,q.qdesc,
t4.qid,t4.svalue1,t4.svalue2,t4.svalue3
INTO tpAverage
FROM #t4 t4
INNER JOIN questionaires q ON q.qid=t4.qid
INNER JOIN groupq g ON g.groupid = q.groupid
INNER JOIN topics tp ON tp.topicid = g.topicid
ORDER BY tp.topicid, qnum, t4.qid
-- SELECT * FROM tpAverage
SET NOCOUNT OFF
GO
Dim cnn As New SqlConnection(Constants.SQLConnectionString)
Dim cmd As New SqlCommand
Dim cmd As New SqlCommand("spAverage", cnn)
cnn.Open()
cmd.CommandType = CommandType.StoredProcedure
Dim prm1 As SqlParameter = cmd.Parameters.Add("@sdate",
txtsdate.Text)
Dim prm2 As SqlParameter = cmd.Parameters.Add("@edate",
txtedate.Text)
cmd.ExecuteNonQuery(CommandBehavior.CloseConnection)
The spAverage does not return any resultset, but it does create a new
table with the all the rows based on the date range parameter that i
passed.
but right after i execute the sp and i check the table that was
created. its empty..altho i know there should be rows in there.
anybody have this problem as well.
Please HELP
here's my sp.
CREATE PROCEDURE spAverage @sdate NVARCHAR(10),@edate NVARCHAR(10)
AS
SET NOCOUNT ON
SET @sdate = CONVERT(NVARCHAR(8),CAST(@sdate AS DATETIME),112)
SET @edate = CONVERT(NVARCHAR(8),CAST(@edate AS DATETIME),112)
IF not object_id('tempdb..#t1') is null
DROP TABLE #t1
SELECT r.qid,svalue1 = AVG(CAST(r.surveyvalue AS DECIMAL)) INTO #T1
FROM groupq g
INNER JOIN questionaires q ON q.groupid = g.groupid
INNER JOIN result r ON r.qid = q.qid
INNER JOIN participant p ON p.participantid=r.participantid
INNER JOIN lkcourse l ON l.courseid= p.levelid
WHERE q.ratetype IN (1,2) and surveyvalue is not null and
surveyvalue <> 0 AND l.grp IN ('G')
AND (CONVERT(NVARCHAR(8),p.EntryDate,112) BETWEEN @sdate AND
@edate)
GROUP BY r.qid
order by r.qid
if not object_id('tempdb..#t2') is null
drop table #t2
select qid2=r.qid,svalue2 = AVG(CAST(r.surveyvalue AS DECIMAL)) INTO
#T2
FROM groupq g
INNER JOIN questionaires q ON q.groupid = g.groupid
INNER JOIN result r ON r.qid = q.qid
INNER JOIN participant p ON p.participantid=r.participantid
INNER JOIN lkcourse l ON l.courseid= p.levelid
WHERE q.ratetype IN (1,2) and surveyvalue is not null and
surveyvalue <> 0 AND l.grp IN ('M')
AND (CONVERT(NVARCHAR(8),p.EntryDate,112) BETWEEN @sdate AND
@edate)
GROUP BY r.qid
order by r.qid
if not object_id('tempdb..#t3') is null
drop table #t3
select qid3=r.qid,svalue3 = AVG(CAST(r.surveyvalue AS DECIMAL)) INTO
#T3
FROM groupq g
INNER JOIN questionaires q ON q.groupid = g.groupid
INNER JOIN result r ON r.qid = q.qid
INNER JOIN participant p ON p.participantid=r.participantid
INNER JOIN lkcourse l ON l.courseid= p.levelid
WHERE q.ratetype IN (1,2) and surveyvalue is not null and
surveyvalue <> 0 AND l.grp IN ('P')
AND (CONVERT(NVARCHAR(8),p.EntryDate,112) BETWEEN @sdate AND
@edate)
GROUP BY r.qid
order by r.qid
if not object_id('tempdb..#t4') is null
drop table #t4
SELECT * INTO #T4 FROM #T1 t1
FULL JOIN #T2 t2 ON t2.qid2 = t1.qid
FULL JOIN #T3 t3 ON t3.qid3 = t1.qid
UPDATE #T4 SET qid=ISNULL(qid2,qid3) WHERE ISNULL(qid,'')=''
if EXISTS(select [name] from sysobjects where [name] = 'tpAverage')
DROP TABLE tpAverage
select tp.topicid,tp.topicdesc,g.qnum,g.groupdesc,q.qdesc,
t4.qid,t4.svalue1,t4.svalue2,t4.svalue3
INTO tpAverage
FROM #t4 t4
INNER JOIN questionaires q ON q.qid=t4.qid
INNER JOIN groupq g ON g.groupid = q.groupid
INNER JOIN topics tp ON tp.topicid = g.topicid
ORDER BY tp.topicid, qnum, t4.qid
-- SELECT * FROM tpAverage
SET NOCOUNT OFF
GO