Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 22nd, 2006, 03:17 PM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default stored procedure

Hi,
I have the following recordset
RsLatestCmm.Open "SELECT Top " & intHomepageCmm & " CID,CmmName,CmmStatus,date_created FROM Cmm_List where CmmStatus=1 ORDER BY date_created desc",conn,0,1

I have converted it into an sp like this
CREATE PROCEDURE [cmmSP_latestCmm] AS
SELECT Top @intHomepageCmm CID,CmmName,CmmStatus,date_created FROM Cmm_List where CmmStatus=1 ORDER BY date_created desc
GO

but I get error for intHomepageCmm
I have considered it as parameter
what should I do?
this intHomepageCmm gets the value from the database table

  #2 (permalink)  
Old July 26th, 2006, 09:17 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I think what your saying is that the value in your stored procedure, @intHomepageCmm, is based upon the value in another database table so what you need to do is this:

CREATE PROCEDURE cmmSP_latestCMM AS
DECLARE @intHomePageCmm as int
SET @intHomePageCmm = SELECT [value] From [table] Where [where clause]

SELECT TOP @intHomePageCmm CID, CmmName, CmmStatus, Date_created from Cmm_List where CmmStatus = 1 ORDER BY date_created desc

hth


"The one language all programmers understand is profanity."
  #3 (permalink)  
Old July 31st, 2006, 03:40 AM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot for your reply

  #4 (permalink)  
Old July 31st, 2006, 04:04 AM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get error this error when creating it in ms sql
Incorrect syntax near the keyword 'SELECT'
this is my sp:
CREATE PROCEDURE [cmmSP_latestCmm] AS
DECLARE @intHomePageCmm as int
SET @intHomePageCmm = SELECT HomepageCmm From cmm_setting
SELECT Top @intHomePageCmm CID,CmmName,CmmStatus,date_created FROM Cmm_List where CmmStatus=1 ORDER BY date_created desc

GO


  #5 (permalink)  
Old July 31st, 2006, 06:39 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

are you using MS SQL or MySQL?

"The one language all programmers understand is profanity."
  #6 (permalink)  
Old August 1st, 2006, 03:28 AM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ms sql

  #7 (permalink)  
Old August 1st, 2006, 07:42 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I probably should point this out:

In MS SQL 2000 the TOP keyword MUST be used as follows:
    SELECT TOP 1 * from [table]

In MS SQL 2005 the TOP keyword can be used as follows:
    SELECT TOP 1 * from [table]
    or
    Declare @nTop as int
    Set @nTop = 1
    SELECT Top (@nTop) * from [table]

In plain english, in SQL 2000 Top must be followed by a literal in 2005 it can be followed by a literal or a variable and, as such, my above code will only work on SQL 2005.


"The one language all programmers understand is profanity."


Similar Threads
Thread Thread Starter Forum Replies Last Post
stored procedure prashant_telkar SQL Server 2000 1 July 9th, 2007 07:57 AM
Stored Procedure jezywrap SQL Server ASP 1 January 3rd, 2007 12:29 AM
stored procedure kdm260 SQL Server 2000 2 June 19th, 2006 04:45 PM
Stored Procedure rajanikrishna SQL Server 2000 0 July 18th, 2005 05:01 AM
Help About Stored Procedure zhuge6 BOOK: ASP.NET Website Programming Problem-Design-Solution 3 May 20th, 2005 09:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.