Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about a cursor 2

Status
Not open for further replies.

FALCONSEYE

Programmer
Jul 30, 2004
1,158
US
i have the following cursor
declare PurchasedProductInsert cursor
keyset
global
for
select bundlename
from customer, orders, addressbook, orderitem
where customer.customerid = orders.customerid
and addressbook.customerid = customer.customerid
and orderstatusid in (1,2) -- successfull orders
and datediff(day, orders.orderdate, getdate()) = 1 -- records from yesterday only
and orders.orderid = orderitem.orderid

declare @bundlename varchar(50),

@prodId int

open PurchasedProductInsert
fetch next from PurchasedProductInsert into @bundlename
set nocount on
while @@fetch_status = 0
begin

-- find whether the product exists in the Products table, if not make an insert
use email
select @prodid = ProductID from Products where productname = '@bundlename'
if @@ROWCOUNT = 0
--new product
begin
/*insert into Products(ProductName, ProductNotes, Enabled, enableSubscription)
values (@bundlename, null, 1, 0)
*/
print 'prod name= '+convert(varchar(50),@bundlename)

end
else
begin
print 'SAME AS ABOVE'
end

fetch next from PurchasedProductInsert into @bundlename

end
close PurchasedProductInsert
deallocate purchasedproductinsert

I am trying to find if a product exists. If so, then print SAME AS ABOVE. If not print the product name. For some reason, when i see the output it looks like

prod name= Windows®
prod name= Windows®
prod name= HTML
prod name= Photoshop 7.0
prod name= HTML
prod name= Microsoft® Access
prod name= Excel

as you will see my product check fails. can someone please help me? what am i doing wrong? thanks in advance
 
iknow this is stupid but some time si have problems if my if are not enclosed try
Code:
if (@@ROWCOUNT = 0)
 
Get rid of the single quotes around your variable:

Code:
select @prodid = ProductID from Products where productname = [red]'[/red]@bundlename[red]'[/red]

--James
 
wow that was crazy. I took both of your suggestions and it worked. Thank you very much...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top