Skip to main content
Inspiring
September 20, 2007
Question

SQL - check multiple tables with one form - Stored Procedure ?

  • September 20, 2007
  • 1 reply
  • 235 views
I have a form and I want to check 3 different tables with that form.
Below, I've attempted to do it but I am sure it will not do what I want.

Expert SQL heads are probably exploding from all the mistakes I've made
in this but how do you pull in results from one form and check multiple
tables using a SP?

Thanks
---------------------------

CREATE PROCEDURE nameeddddf_searchresults
@searchform varchar (6000),
@searchone varchar (100),
@searchtwo varchar (20),
@searchthree varchar (6000)
AS
SELECT P.ID AS ProductID, P.Name, P.ProdID, P.Price, P.ClearSale,
P.SalePrice, P.ShipCost, G.gid, G.pid AS Gpid, G.ord, D.PID AS DPID,
D.Paragraph, C.Category
FROM atblProducts P INNER JOIN Groups G ON P.ID = G.pid INNER JOIN PCat
PC ON G.gid = PC.gid INNER JOIN Categories C ON PC.cid = C.ID LEFT JOIN
Description D ON G.gid = D.PID
WHERE ((PC.cid <> '113') AND (PC.cid <> '107') AND (PC.cid <> '106') AND
(PC.cid <> '105') AND (PC.cid <> '104') AND (PC.cid <> '103') AND
(PC.cid <> '102') AND (PC.cid <> '101')
AND (PC.cid <> '100') AND (PC.cid <> '99') AND (PC.cid <> '98')) AND
(P.Price <> 10.25 AND P.Price IS NOT NULL AND P.Price <> 0 AND P.Active
<> 0 AND PC.ord = 0 )
AND (P.Name LIKE '%' + @searchform + '%' OR P.ID LIKE '%' +
@searchform + '%' OR D.Paragraph LIKE '%' + @searchform + '%') AND
C.Active <> 0
ORDER BY G.gid, G.ord, P.ID, P.Name
GO
This topic has been closed for replies.

1 reply

Inspiring
September 20, 2007
Ok, I sort of answered it on my own.





Lee wrote:
> I have a form and I want to check 3 different tables with that form.
> Below, I've attempted to do it but I am sure it will not do what I want.
>
> Expert SQL heads are probably exploding from all the mistakes I've made
> in this but how do you pull in results from one form and check multiple
> tables using a SP?
>
> Thanks
> ---------------------------
>
> CREATE PROCEDURE nameeddddf_searchresults
> @searchform varchar (6000),
> @searchone varchar (100),
> @searchtwo varchar (20),
> @searchthree varchar (6000)
> AS
> SELECT P.ID AS ProductID, P.Name, P.ProdID, P.Price, P.ClearSale,
> P.SalePrice, P.ShipCost, G.gid, G.pid AS Gpid, G.ord, D.PID AS DPID,
> D.Paragraph, C.Category
> FROM atblProducts P INNER JOIN Groups G ON P.ID = G.pid INNER JOIN PCat
> PC ON G.gid = PC.gid INNER JOIN Categories C ON PC.cid = C.ID LEFT JOIN
> Description D ON G.gid = D.PID
> WHERE ((PC.cid <> '113') AND (PC.cid <> '107') AND (PC.cid <> '106') AND
> (PC.cid <> '105') AND (PC.cid <> '104') AND (PC.cid <> '103') AND
> (PC.cid <> '102') AND (PC.cid <> '101')
> AND (PC.cid <> '100') AND (PC.cid <> '99') AND (PC.cid <> '98')) AND
> (P.Price <> 10.25 AND P.Price IS NOT NULL AND P.Price <> 0 AND P.Active
> <> 0 AND PC.ord = 0 )
> AND (P.Name LIKE '%' + @searchform + '%' OR P.ID LIKE '%' +
> @searchform + '%' OR D.Paragraph LIKE '%' + @searchform + '%') AND
> C.Active <> 0
> ORDER BY G.gid, G.ord, P.ID, P.Name
> GO