473,386 Members | 2,078 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,386 software developers and data experts.

Stored Procedure Range Not Working

Hi All,
I am trying to write a basic stored procedure to return a range of
values but admit that I am stumped. The procedure syntax used is:

ALTER PROCEDURE Rpt_LegacyPurchaseOrderSp(

@StartPoNumber PONumberType = 'Null',
@FinishPoNumber PONumberType = 'Null')

AS

SET @StartPoNumber = 'PO_NUMBER_POMSTR'
SET @FinishPoNumber = 'PO_NUMBER_POMSTR'

SELECT IPPOMST_SID, --Start tbl_IPPOMST
PO_NUMBER_POMSTR,
VENDOR_NUMBER_POMSTR,
SHIP_NUMBER_POMSTR,
CHANGE_ORDER_POMSTR,
FOB_POINT_POMSTR,
ROUTING_POMSTR,
DATE_ISSUED_POMSTR,
DATE_LAST_RECPT_POMSTR,
CONTACT_PERSON_1_POMSTR,
PREPAID_COLLECT_POMSTR,
TERMS_POMSTR,
AMOUNT_ESTIMATED_POMSTR,
AMOUNT_RECEIVED_POMSTR,
AMOUNT_PAID_POMSTR,
LOCATION_CODE_POMSTR,
SHIPPING_POINT_POMSTR,
PRINT_IND_POMSTR,
BUYER_POMSTR,
SHIPMENT_POMSTR,
STATUS_POMSTR,
CURRENCY_POMSTR,
CURRENCY_STATUS_POMSTR,
AMOUNT_EST_CUR_POMSTR,
AMOUNT_REC_CUR_POMSTR,
AMOUNT_PAID_CUR_POMSTR, --Finish tbl_IPPOMST
IPPOITM_SID, --Start tbl_IPPOITM
PO_NUMBER_POITEM,
ITEM_NUMBER_POITEM,
CATEGORY_POITEM,
DESCRIPTION_POITEM,
VENDOR_NUMBER_POITEM,
DATE_ORIGINAL,
DATE_RESCHEDULED,
ACCOUNT_NUMBER_POITEM,
STOCK_NUMBER_POITEM,
JOB_NUMBER_POITEM,
RELEASE_WO_POITEM,
QUANTITY_ORDERED_POITEM,
QUANTITY_RECVD_POITEM,
UOM_POITEM,
UNIT_WEIGHT_POITEM,
UNIT_COST_POITEM,
EXTENDED_TOTAL_POITEM,
MATERIAL_NUMBER_POITEM,
COMPLETE_POITEM,
LOCATION_CODE_POITEM,
INSPECTION_POITEM,
BOM_ITEM_POITEM,
COST_ACCOUNT_POITEM,
CHANGE_ORDER_POITEM,
TAX_CODE_POITEM,
ISSUE_CODE_POITEM,
QUANTITY_INSPECT_POITEM,
EXC_RATE_CURR_POITEM,
UNIT_COST_CURR_POITEM,
EXTENDED_TOTAL_CURR_POITEM,
PLANNER_POITEM,
BUYER_POITEM --Finish tbl_IPPOITM
IPVENDM_SID, --Start tbl_IPVENDM
VENDOR_NUMBER_VENMSTR,
VENDOR_NAME_VENMSTR,
ADDRESS_LINE_1_VENMSTR,
ADDRESS_LINE_2_VENMSTR,
ADDRESS_LINE_3_VENMSTR,
CITY_VENMSTR,
STATE_VENMSTR,
ZIP_CODE_VENMSTR,
COUNTRY_VENMSTR --Finish tbl_IPVENDM

FROM tbl_IPPOMST
JOIN tbl_IPPOITM
ON tbl_IPPOITM.PO_NUMBER_POITEM = tbl_IPPOMST.PO_NUMBER_POMSTR
JOIN tbl_IPVENDM
on tbl_IPVENDM.VENDOR_NUMBER_VENMSTR = tbl_IPPOMST.VENDOR_NUMBER_POMSTR
WHERE tbl_IPPOMST.PO_NUMBER_POMSTR >= @StartPoNumber AND
tbl_IPPOMST.PO_NUMBER_POMSTR <= @FinishPoNumber

Basically, no rows are returned for the valid (records in database)
range I enter. I have been troubleshopoting the syntax. This has
involved commenting out references to @FinishPoNumber so in effect I
just pass in a valid PO Number using @StartPoNumber parameter. This
works in terms of returning all 76545 PO records.

Can anyone help me to identify why this syntax will not return a range
of PO records that fall between @StartPoNumber and @FinishPoNumber?

Any help would be greatly appreciated.

Many Thanks*

rohan

* & Merry Christmas!

Dec 22 '06 #1
2 1615
red vertigo (ro***********@hotmail.com) writes:
I am trying to write a basic stored procedure to return a range of
values but admit that I am stumped. The procedure syntax used is:

ALTER PROCEDURE Rpt_LegacyPurchaseOrderSp(

@StartPoNumber PONumberType = 'Null',
@FinishPoNumber PONumberType = 'Null')

AS

SET @StartPoNumber = 'PO_NUMBER_POMSTR'
SET @FinishPoNumber = 'PO_NUMBER_POMSTR'

SELECT IPPOMST_SID, --Start tbl_IPPOMST
...
FROM tbl_IPPOMST
JOIN tbl_IPPOITM
ON tbl_IPPOITM.PO_NUMBER_POITEM = tbl_IPPOMST.PO_NUMBER_POMSTR
JOIN tbl_IPVENDM
on tbl_IPVENDM.VENDOR_NUMBER_VENMSTR = tbl_IPPOMST.VENDOR_NUMBER_POMSTR
WHERE tbl_IPPOMST.PO_NUMBER_POMSTR >= @StartPoNumber AND
tbl_IPPOMST.PO_NUMBER_POMSTR <= @FinishPoNumber

Basically, no rows are returned for the valid (records in database)
range I enter. I have been troubleshopoting the syntax. This has
involved commenting out references to @FinishPoNumber so in effect I
just pass in a valid PO Number using @StartPoNumber parameter. This
works in terms of returning all 76545 PO records.

Can anyone help me to identify why this syntax will not return a range
of PO records that fall between @StartPoNumber and @FinishPoNumber?
With the sample code posted, the procedure only returns data if there any
rows with the value PO_NUMBER_POMSTR. Are there any such rows?

If you comment out the initial SET statements, and call the procedure
like this:

EXEC Rpt_LegacyPurchaseOrderSp @StartPoNumber = 'Putte'

you will not get any rows back, because @FinnishPoNumber is the string
'Null' which is before Putte.

If you change the procedure like this, it may work better:

ALTER PROCEDURE Rpt_LegacyPurchaseOrderSp(

@StartPoNumber PONumberType = NULL,
@FinishPoNumber PONumberType = NULL) -- No quotes around NULL

-- Remove SET statements

SELECT ...
...
WHERE tbl_IPPOMST.PO_NUMBER_POMSTR >=
isnull(@StartPoNumber, SELECT MIN(PO_NUMBER_POMSTR)
FROM tbl_IPPOMST)
AND tbl_IPPOMST.PO_NUMBER_POMSTR <=
isnull(@FinishPoNumber, SELECT MAX(PO_NUMBER_POMSTR)
FROM tbl_IPPOMST)

Normally, you should use coalesce to replace NULL with another value, but
in this special case isnull() may be better of performance reasons.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Dec 22 '06 #2

Erland Sommarskog wrote:
red vertigo (ro***********@hotmail.com) writes:
I am trying to write a basic stored procedure to return a range of
values but admit that I am stumped. The procedure syntax used is:

ALTER PROCEDURE Rpt_LegacyPurchaseOrderSp(

@StartPoNumber PONumberType = 'Null',
@FinishPoNumber PONumberType = 'Null')

AS

SET @StartPoNumber = 'PO_NUMBER_POMSTR'
SET @FinishPoNumber = 'PO_NUMBER_POMSTR'

SELECT IPPOMST_SID, --Start tbl_IPPOMST
...
FROM tbl_IPPOMST
JOIN tbl_IPPOITM
ON tbl_IPPOITM.PO_NUMBER_POITEM = tbl_IPPOMST.PO_NUMBER_POMSTR
JOIN tbl_IPVENDM
on tbl_IPVENDM.VENDOR_NUMBER_VENMSTR = tbl_IPPOMST.VENDOR_NUMBER_POMSTR
WHERE tbl_IPPOMST.PO_NUMBER_POMSTR >= @StartPoNumber AND
tbl_IPPOMST.PO_NUMBER_POMSTR <= @FinishPoNumber

Basically, no rows are returned for the valid (records in database)
range I enter. I have been troubleshopoting the syntax. This has
involved commenting out references to @FinishPoNumber so in effect I
just pass in a valid PO Number using @StartPoNumber parameter. This
works in terms of returning all 76545 PO records.

Can anyone help me to identify why this syntax will not return a range
of PO records that fall between @StartPoNumber and @FinishPoNumber?

With the sample code posted, the procedure only returns data if there any
rows with the value PO_NUMBER_POMSTR. Are there any such rows?

If you comment out the initial SET statements, and call the procedure
like this:

EXEC Rpt_LegacyPurchaseOrderSp @StartPoNumber = 'Putte'

you will not get any rows back, because @FinnishPoNumber is the string
'Null' which is before Putte.

If you change the procedure like this, it may work better:

ALTER PROCEDURE Rpt_LegacyPurchaseOrderSp(

@StartPoNumber PONumberType = NULL,
@FinishPoNumber PONumberType = NULL) -- No quotes around NULL

-- Remove SET statements

SELECT ...
...
WHERE tbl_IPPOMST.PO_NUMBER_POMSTR >=
isnull(@StartPoNumber, SELECT MIN(PO_NUMBER_POMSTR)
FROM tbl_IPPOMST)
AND tbl_IPPOMST.PO_NUMBER_POMSTR <=
isnull(@FinishPoNumber, SELECT MAX(PO_NUMBER_POMSTR)
FROM tbl_IPPOMST)

Normally, you should use coalesce to replace NULL with another value, but
in this special case isnull() may be better of performance reasons.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Hi Erland,
Thankyou very much for replying to my post, for your insight and
suggestions. I will make changes and see if I can get this to work.

rohan:)

Dec 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
4
by: MD | last post by:
I am trying to create a dynamic SQL statement to create a view. I have a stored procedure, which based on the parameters passed calls different stored procedures. Each of this sub stored procedure...
3
by: Ryan.Chowdhury | last post by:
This is a general question regarding the use of view and stored procedures. I'm fairly new to databases and SQL. I've created a SQL database using an Access Data Project ("ADP") and I'm...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
2
by: syntego | last post by:
We commonly use triggers to log changes to our main tables to historical log tables. In the trigger, we create a concatenated string of the old values by casting them as follows: ...
0
by: gregoryday | last post by:
I am having a problem with creating a stored procedure. The premise underwhich we are operating is the following: We are working with two tables. The first table simply stores an integer value...
1
by: flickimp | last post by:
Hi I have a stored procedure on SQL Server 2000 called: .Capacity_Planning.dbo.sp_flickimp_test I have an Excel Sheet with the 2 paramters for the Stored procedure in cells A1 and B1. How...
0
by: pelusa | last post by:
If possible I need help to write a stored procedure, or pseudocode, that looks into a table named numbers_ranges and retrieves the next unused value. The table currenlty has the following...
2
by: acw | last post by:
On a SQL Server 2000 db I would like to setup a stored procedure that accesses couple tables and runs the extended stored procedure xp..cmdshell. The goal is to grant users with limited privileges...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.