Click here to Skip to main content
15,920,438 members
Home / Discussions / Database
   

Database

 
GeneralHelp with crystal reports!!!! Pin
korso_rogan17-Aug-05 23:39
korso_rogan17-Aug-05 23:39 
GeneralCannot open backup device Pin
dhtuan17-Aug-05 22:21
dhtuan17-Aug-05 22:21 
Generalusing describe with MS Access Pin
mhmo17-Aug-05 6:57
mhmo17-Aug-05 6:57 
GeneralRe: using describe with MS Access Pin
Rob Graham17-Aug-05 10:20
Rob Graham17-Aug-05 10:20 
GeneralDisconnected Data Question Pin
matthias s.17-Aug-05 6:26
matthias s.17-Aug-05 6:26 
GeneralRe: Disconnected Data Question Pin
ToddHileHoffer17-Aug-05 9:42
ToddHileHoffer17-Aug-05 9:42 
GeneralRe: Disconnected Data Question Pin
miah alom19-Aug-05 6:30
miah alom19-Aug-05 6:30 
QuestionSQL 2000 - IF / THEN bug? Pin
Anthony Ford17-Aug-05 5:11
Anthony Ford17-Aug-05 5:11 
Several times I have run into what I think is a bug in SQL Server 2000, but I haven't been able to verify it externally. Hopefully someone can help me do so, or identify what I'm doing wrong, or suggest an alternate technique to use.

Short descripttion: In a stored procedure, if I place a query inside an IF block and another inside the ELSE block the procedure works fine in SQL Server Query Analyzer. But... I get no results returned to an ADO recordset.

---------------------------

Long Description and code sample:

The purpose of the following stored procedure is to allow me to specify whether or not to limit the query to a specific VendorID value. The queries in the IF and ELSE blocks are exactly the same, except that the one in the ELSE block includes the VendorID filter in the WHERE clause.

When I execute this procedure from within SQL Query Analyzer, I get exactly the behavior I expect:

If I pass in 0 as the 3rd parameter, it will return any records matching the LastName and ZipCode parameters regardless of which Vendor: sp_PromoOrderSearch 'Doe', '98765', 0


If I pass in a non 0 number for VendorID, records will only be returned if all three values match across both tables: sp_PromoOrderSearch 'Doe', '98765', 2

So, the procedure works exactly as designed. The problem comes when I attempt to use this procedure from ADO. No matter what I pass in, I get no results at all. Now before you go wondering if I'm passing in parameters correctly, consider this: If I rip out the IF / THEN structure and only use one or the other query by itself, EACH of them works fine and returns records to my ADO recordset.

Right now my only solution is to use different stored procedures for each purpose, but I hate that. Any help?

Thanks in advance.


---------------------


CREATE PROCEDURE sp_PromoOrderSearch
@LastName varchar(255),
@ZipCode varchar(255),
@VendorID int
AS
-- Vendor 0 is global and can search among all vendors
IF (@VendorID = 0)
BEGIN
SELECT
pd.[custom_id], pd.[first_name], pd.[last_name],
pd.[address1], pd.[address2], pd.[phone_number],
pd.[email], pd.[qualified_date], v.[v_name]
FROM [promo_data] pd
JOIN promotion p ON p.p_code = pd.promo_code
JOIN vendor v ON v.v_id = p.v_id
WHERE
(
(pd.[last_name] = @LastName)
AND
(pd.[zip] = @ZipCode)
)
ORDER BY
pd.[last_name] ASC,
pd.[first_name] ASC
END
ELSE
BEGIN
SELECT
pd.[custom_id], pd.[first_name], pd.[last_name],
pd.[address1], pd.[address2], pd.[phone_number],
pd.[email], pd.[qualified_date], v.[v_name]
FROM [promo_data] pd
JOIN promotion p ON p.p_code = pd.promo_code
JOIN vendor v ON v.v_id = p.v_id
WHERE
(
(pd.[last_name] = @LastName)
AND
(pd.[zip] = @ZipCode)
AND
(v.v_id = @VendorID)
)
ORDER BY
pd.[last_name] ASC,
pd.[first_name] ASC
END
GO

--------



Anthony
AnswerRe: SQL 2000 - IF / THEN bug? Pin
ToddHileHoffer17-Aug-05 9:46
ToddHileHoffer17-Aug-05 9:46 
GeneralRe: SQL 2000 - IF / THEN bug? Pin
Anthony Ford17-Aug-05 10:02
Anthony Ford17-Aug-05 10:02 
GeneralRe: SQL 2000 - IF / THEN bug? Pin
ToddHileHoffer17-Aug-05 10:42
ToddHileHoffer17-Aug-05 10:42 
GeneralSql server Pin
chandru_inbox17-Aug-05 0:29
chandru_inbox17-Aug-05 0:29 
GeneralRe: Sql server Pin
Yulianto.18-Aug-05 16:44
Yulianto.18-Aug-05 16:44 
GeneralRe: Sql server Pin
miah alom19-Aug-05 6:34
miah alom19-Aug-05 6:34 
GeneralNeed advice on numerical data types for numbers like ##,###.## Pin
FTrader16-Aug-05 20:41
FTrader16-Aug-05 20:41 
GeneralRe: Need advice on numerical data types for numbers like ##,###.## Pin
Colin Angus Mackay16-Aug-05 22:28
Colin Angus Mackay16-Aug-05 22:28 
GeneralRe: Need advice on numerical data types for numbers like ##,###.## Pin
FTrader16-Aug-05 23:16
FTrader16-Aug-05 23:16 
GeneralRe: Need advice on numerical data types for numbers like ##,###.## Pin
Dan Neely17-Aug-05 10:38
Dan Neely17-Aug-05 10:38 
GeneralRe: Need advice on numerical data types for numbers like ##,###.## Pin
FTrader17-Aug-05 12:44
FTrader17-Aug-05 12:44 
GeneralRe: Need advice on numerical data types for numbers like ##,###.## Pin
Dan Neely18-Aug-05 7:57
Dan Neely18-Aug-05 7:57 
GeneralSome info about .NET decimal Pin
FTrader17-Aug-05 1:57
FTrader17-Aug-05 1:57 
QuestionDeleted entries reappearing in Access 2000 DB? Pin
mav.northwind16-Aug-05 20:28
mav.northwind16-Aug-05 20:28 
Questionhow to accessing Paradox use ADO Pin
ebinaini16-Aug-05 19:20
ebinaini16-Aug-05 19:20 
General.NET SQL Stored Procedures Pin
Carl Mercier16-Aug-05 6:36
Carl Mercier16-Aug-05 6:36 
GeneralTriggers Problem [modified] Pin
Faheem Habib15-Aug-05 23:23
Faheem Habib15-Aug-05 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.