473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

STORED PROCEDURE not working properly

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.CloseConnectio n)

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

Jul 21 '05 #1
0 1032

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
4
by: Mike | last post by:
Hello, I'm currently working on debugging a very large DTS package that was created by someone else for the purpose of importing data into my company's database. The data is mainly...
9
by: Ralph Cramden | last post by:
I'm writing a VB6 app which calls several stored procedures on my SQL Server DB. The first stored procedure must complete its inserts before the second stored procedure can query the modified...
11
by: Bã§TãRÐ | last post by:
I have been working on this particular project for a little over 2 weeks now. This product contains between 700-900 stored procedures to handle just about all you can imagine within the product. I...
3
by: wxbuff | last post by:
I have a report based on our product names that consists of two parts. Both insert data into a temporary table. 1. A single grouped set of results based on all products 2. Multiple tables based...
9
by: Nikolay Petrov | last post by:
How to fill DataSet from stored procedure?
22
by: M K | last post by:
Heres my SP: ( i am trying to add more than 1 field but get the same error no matter how many i try to add, i thought i would try to insert the primary key only and work up from there but the...
5
by: Pedro Vera | last post by:
I am helping somebody setup one of the asp.net starter kits. I converted it from sql express to sql server with no real issues, and I got it running local perfectly. On my first attempt to run...
2
by: acw | last post by:
On a SQL Server 2000 db I would like to setup a stored procedure that accesses couple tables and runs the extended stored procedure xp..cmdshell. The goal is to grant users with limited privileges...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.