Re: STORED PROCEDURE is not working HELP

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: William \(Bill\) Vaughn (billvaRemoveThis_at_nwlink.com)
Date: 08/06/04


Date: Thu, 5 Aug 2004 19:34:02 -0700

1) Turn on the SQL Profiler to see what's getting executed.
2) I would setup the parameter as a DateTime or SmallDateTime (depending on
how it's defined in the SP).
3) It would help to see the SP code. What tables does it create? If they are
#temp tables, consider that these are dropped after the SP that creates them
ends.

-- 
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Joriz" <google@joriz.is-a-geek.net> wrote in message
news:7d49ea6b.0408041345.7ae4a695@posting.google.com...
> 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


Relevant Pages

  • Re: STORED PROCEDURE is not working HELP
    ... Have an opinion on the effectiveness of Microsoft Embedded newsgroups? ... > FROM groupq g ... > INNER JOIN questionaires q ON q.groupid = g.groupid ...
    (microsoft.public.dotnet.framework.adonet)
  • RE: Executing Looping SP within DTS (SP provided)
    ... I haven't included the DTS Package. ... Package simply runs this procedure using execute sql task. ... INNER JOIN tbl_country cty ... --- Now load volume data by comparing the two months cumulative totals ...
    (microsoft.public.sqlserver.dts)
  • SQL Server 2000 UDF Intermittent Slow Execution
    ... Two identical SQL Server databases (DB1 backed up and ... to execute DB1.dbo.GetSchPaymentsTD took less than a millisecond ... identical code) after which the execution was lightning fast (just ... INNER JOIN dbo.tblPaymentTemplate PT ...
    (comp.databases.ms-sqlserver)
  • Re: access SQL query
    ... the records in a field from one of the tables and update/insert them ... from tblSharesSpreadsheet inner join tblShares on ... your join criteria in the Criteria box for LifetimeOfShare. ... eventually execute (via the red! ...
    (comp.databases.ms-access)
  • Re: Left Join woes
    ... That join is ambiguous, meaning if you execute the inner join first, then ... join you want, the second query use the first query, as table, and execute ...
    (microsoft.public.access.queries)