473,396 Members | 1,866 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,396 software developers and data experts.

IF statement question in stored procedure

The following stored procedure is trying to get a page id, but if it can't find it, then it gets the page id from it's 'parent'. for some reason, it always executes the longer query, but i don't want it to do this when the page_ID can be found using the provided category_ID. this problem is driving me crazy as I am quite unfamiliar with stored procedures in general. thanks!

ALTER PROCEDURE [dbo].[GetParentPage] (@Category_ID int) AS
SELECT Category_Page FROM Categories WHERE Category_ID in
(SELECT Category_Parent_ID FROM Categories WHERE Category_ID = @Category_ID)
IF @@ROWCOUNT = 0
BEGIN
SELECT Category_Page FROM Categories WHERE Category_ID = @Category_ID
END
ELSE
BEGIN
SELECT Category_Page FROM Categories WHERE Category_ID in
(SELECT Category_Parent_ID FROM Categories WHERE Category_ID = @Category_ID)
END
Nov 14 '07 #1
0 959

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jeff Mason | last post by:
Consider the following (questionable, to be sure, but syntactally legal) stored procedure (using the Northwind database): Create Procedure Test As Return (Select Count(*) From Orders) Select *...
4
by: Raquel | last post by:
This is regarding SQL stored procedures. The guide says this about handler declaration in SQL procedures: "handler declaration can specify a SQL-procedure-statement. SQL-procedure-statement is a...
2
by: Rhino | last post by:
Is there some kind of requirement that a DECLARE CONTINUE HANDLER statement follow the DECLARE CURSOR statement in an SQL stored procedure? I am running DB2 V8.2.1 on Windows XP and am writing my...
6
by: Terentius Neo | last post by:
Is it possible to combine (in DB2 UDB 8.1) a stored procedure and a select statement? I mean something like this: Select c.number, call procedure( c.number ) as list from table c With best...
2
by: Rajat Katyal | last post by:
Hi: I prepare the statement for execution as follows: PREPARE query(text) as SELECT count(*) FROM transform_customer_billing where inv_no = $1; The problem is Iam not able to execute this...
0
by: Scarab | last post by:
Hi all, When I use following sql to get data in stored procedure, error occurs: insert into #tmp EXECUTE dbo.prc_1 @date1,@date1 Here is the source code, Thanks CREATE TABLE ( NULL , ...
6
by: Not4u | last post by:
Hello Config : SQL 2000 on WIN 2000 (IIS 5.0) In my ASP page for some queries i have this error : Microsoft OLE DB Provider for SQL Server error '80040e31' Timeout expired
2
by: Beowulf | last post by:
If I run this statement in Query Analyzer, it properly returns 1 for my testing table. But if I put the statement into a stored procedure, the stored procedure returns NULL. What am I doing...
6
by: Szymon Dembek | last post by:
Hello to everyone, I'm currently doing some UDF and stored procedure development in DB2 v.9. I have a problem with the following construct: SET (var_a, var_b) = (select a, b from table1...
2
by: kxyz | last post by:
Hello everyone, I need help with a stored procedure or two. My stored procedures are supposed to check if a certain record exists. If it does exist, then I select everything from that row, as...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.