Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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

Reply With Quote
  #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."
Reply With Quote
  #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

Reply With Quote
  #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


Reply With Quote
  #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."
Reply With Quote
  #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

Reply With Quote
  #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."
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:36 AM.


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