|
-
February 10th, 2000, 06:08 PM
#1
Database- SQL
Is there a way I can loop through a set values returned from a SQL Query apart from using cursors.
Cursors for me wont work cuz the SQL is dynamically built using variables and variable declaration does not work within a cursor declaration.
Heres what the stored procedure looks like :
CREATE procedure spGetSearchProduct1
(
@name varchar(50) = NULL,
@sku varchar(15) = NULL,
@catalogid int = NULL
)
AS
if @catalogid = "" RETURN 0
IF @name=""
BEGIN
IF @sku =""
BEGIN
RETURN 0
END
ELSE
BEGIN
SELECT @sWhere = " prod.sku like '%" + @sku + "%'"
END
END
ELSE
IF @sku=""
BEGIN
SELECT @sWhere = " prod.Name like '%" +@name + "%'"
END
ELSE
BEGIN
SELECT @sWhere = " prod.Name like '%" +@name + "%' and prod.sku like '%" + @sku + "%'"
END
SELECT @sSQL = "SELECT prod.productid, prod.name , prod.ListPrice, prod.stdcost, prod.sku, mfg.mfgcode,mfg.mfgname, ISNULL(mfg.imagefile,'noimage.gif') as graphic1, mfg.homeurl, spr.SupplierId, s.suppliercode FROM Product prod, manufacturer mfg, supplierproductcost spr, supplier s"
SELECT @sSQL = @sSQL + " WHERE prod.mfgid=mfg.mfgid and s.supplierid= spr.supplierid and prod.ProductId = spr.ProductId and prod.CatalogId = "+ convert(varchar(8),@catalogid) + " and " + @sWhere
Exec (@sSQL)
i basically need to loop through the return values of @sSQL and generate an output.
Any suggestions would be deeply appreciated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|