Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 SQL Stored Procedures
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

redbrad0
Advanced Member

USA
3725 Posts

Posted - 22 May 2004 :  12:39:15  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
I have been creating some stored procedures, but having a small problem on just one. When specifying the table name, I have to but the database name in front of it. So an example would be

CREATE procedure sp_CheckThis (@MemberName nvarchar)
as
select MEMBER_ID
from eznetideas.MEMBERS
where NAME = @MemberName
GO

Does anyone know a reason for this?

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 22 May 2004 :  13:46:18  Show Profile
Firstly, never prefix stored procedures with sp_ as this causes SQL Server to presume it is a System stored procedure and will execute slower.

You shouldn't need to specify the database name if the stored proc is in the same db as the table.

Also, specify the size of the nvarchar column
eg
CREATE procedure sp_CheckThis (@MemberName nvarchar(50))

The UK MkIVs Forum
Go to Top of Page

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 22 May 2004 :  14:30:44  Show Profile
If you need to ever specify the database name, then you also need to specify the schema owner as well before the table name.

databasename.schemaowner.tablename

eznetideas.dbo.MEMBERS

but if the table is in the same database as the stored proc then you might as well not specify the database name.

You should also take note of Davids comments as well. If you want to prefix your stored procs with something then anything other than sp_ will do, e.g. usp_

Edited by - pweighill on 22 May 2004 14:31:37
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 22 May 2004 :  18:06:39  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
Oh well I saw on http://www.4guysfromrolla.com/webtech/111499-1.shtml that he named his stuff sp_. I will change it. Basically I am having to specify the username that the sp was created under. I was incorrect in saying it was the database name. So I am hoping to not have to say the username as that would make these scripts not as "generic" and to where they could be used on other sites. Basically what I am doing is creating a snitz forum that uses SP's. I have most of the code done, but was having a problem using if then statments in the SP. do you guys know whats wrong with this?


 CREATE procedure sp_TestSP (@ShowAdminOnly nvarchar(5), @TopicID int)
as
select M.M_NAME, M.M_RECEIVE_EMAIL, M.M_AIM, M.M_ICQ, M.M_MSN, M.M_YAHOO, M.M_TITLE, M.M_HOMEPAGE, M.MEMBER_ID, M.M_LEVEL, M.M_POSTS, M.M_COUNTRY, T.T_DATE, T.T_SUBJECT, T.T_AUTHOR, T.TOPIC_ID, T.T_STATUS, T.T_LAST_EDIT, T.T_LAST_EDITBY, T.T_LAST_POST, T.T_SIG, T.T_REPLIES, C.CAT_STATUS, C.CAT_ID, C.CAT_NAME, C.CAT_SUBSCRIPTION, C.CAT_MODERATION, F.F_STATUS, F.FORUM_ID, F.F_SUBSCRIPTION, F.F_SUBJECT, F.F_MODERATION, T.T_MESSAGE
if @ShowAdminOnly='true'
	, M.M_SIG
end if
FROM dbo.FORUM_TOPICS T, dbo.FORUM_FORUM F, dbo.FORUM_CATEGORY C, dbo.FORUM_MEMBERS M WHERE T.TOPIC_ID = @TopicID AND F.FORUM_ID = T.FORUM_ID AND C.CAT_ID = T.CAT_ID AND M.MEMBER_ID = T.T_AUTHOR
else
Go

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 22 May 2004 :  18:43:09  Show Profile
you can't do that unless you are building up a sql string to execute which would then be pointless.
Have a look at the Case statement

The UK MkIVs Forum
Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 07 June 2004 :  15:15:17  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
Brad,

I started the same thing a couple of months ago. Your best bet would be to pull the SIG all the time and only display it if needed. You could also create two queries and decide which query to pull in the ASP.

Another issue with using cases or if's to change the actual SQL is that you lose the advantage that the query has been precompiled. Since the query can be different with every request the query will be precompiled opposed to having a static query. I tend to use COALESCE() a lot when I might or might not need to pass a variable. Like:

@mname varchar(10) = null
WHERE m.name = COALESCE(@mname,m.name)

If you don't pass the @mname var from the asp page then it will be NULL, using the COALECSE function, the value in the column will be used, resulting in an always true statement. I have used this on searches with very good results.

Hope that helps.

Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 07 June 2004 :  19:26:39  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
Thanks for the reply. So you went thru and change snitz to a pretty much SP forum? I went thru and did all of the included functions and the results seemed pretty good. Seemed to run faster, but wish there was a way to make every query a SP to see how well the site would run.

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 08 June 2004 :  11:47:39  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
hehe, that was/is the plan. I originally was going to make it a MOD. Therefore, I created a page that will create the SPROCS in the database. I also wanted to make it compatible with Access and MSSQL. I have only done the Members Page . Creating the most efficient sprocs that support Access and MSSQL has not been too much fun. Doing it in MSSQL would be a lot easier and more efficient. I am considering doing just that. For example, in MSSQL I could create a single sproc for the posting of a message; you could update counts, last post date, last post member, etc. I am still debating with myself whether to make it an Access version or just MSSQL, which is what I will be using anyways.
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 08 June 2004 :  12:25:50  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
My thought was to just make a mssql version. The way I did it was add a additional field in the config.asp file which looked like below..


strDBType = "sqlserver"
'strDBType = "access"
'strDBType = "mysql"

strDBType2 = "sp" ' # WITH THIS UN COMMENTED THIS FORUM WILL USE STORED PROCEDURES FOR ALOT OF FUNCTIONS
' # IF YOU USE THE ABOVE STORED PROCEDURE YOUR FORUM MOST USE DB FOR AUTHORIZATION
' # AND ALL OF YOUR FORUM TABLES MUST START WITH FORUM_


then in the forum files I was doing this...

		set rsBadWord = Server.CreateObject("ADODB.Recordset")
		If strDBType2="sp" Then
			' # LETS RUN THE STORED PROCEDURE
			Set rsBadWord = my_Conn.Execute ("chkBadWords")
		Else
			strSqlb = "SELECT B_BADWORD, B_REPLACE "
			strSqlb = strSqlb & " FROM " & strFilterTablePrefix & "BADWORDS "
			rsBadWord.open strSqlb, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText
		End If


This way I could turn on and off the SP's

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets

Edited by - redbrad0 on 08 June 2004 12:26:17
Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 08 June 2004 :  12:53:47  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
Did you only do the functions, or did you do all the pages? I was just going to replace the query. In fact, I thought about doing a scipt that would (on unmodded) forums could search for the sql and replace with the respective sproc. But, if it's unmodded then you could just replace the file - so what would be the point.
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 09 June 2004 :  01:03:05  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
I just did all the functions which seemed to really help. I wouldnt even worry about the script, would be very hard to try and figure everything out.

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

sr_erick
Senior Member

USA
1318 Posts

Posted - 09 June 2004 :  09:12:38  Show Profile  Visit sr_erick's Homepage  Send sr_erick a Yahoo! Message
So.....when is an entire forum package going to be released.




Erick
Snowmobile Fanatics

Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 09 June 2004 :  10:11:51  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
Mine will be a while...

erick, are you Access SQLServer based?
Go to Top of Page

sr_erick
Senior Member

USA
1318 Posts

Posted - 09 June 2004 :  12:09:46  Show Profile  Visit sr_erick's Homepage  Send sr_erick a Yahoo! Message
MSSQL, MySQL, or Access. Those are my choices. Right now I'm using MSSQL and continue to develop on it because it does so much more than either MySQL or Access.




Erick
Snowmobile Fanatics

Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 09 June 2004 :  12:14:46  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
OK. I think I'm going to chuck Access support - it will be so much easier to support MSSQL only.
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 09 June 2004 :  19:23:46  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
yep thats the way to go, if you want a test site with a sql database let me know and i can set you up a site to use.

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.44 seconds. Powered By: Snitz Forums 2000 Version 3.4.07