PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > PHP code to Stored Procedure
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
PHP code to Stored Procedure

Réponse
 
LinkBack Outils de la discussion
Vieux 22/09/2007, 08h57   #1
aCe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut PHP code to Stored Procedure

hi all,
i need to convert these simple PHP code into stored procedure :
<?php
$result = mssql_query( "SELECT whid, whcode FROM warehouse" );
while( $wh = mssql_fetch_object( $result ) )
{
$result = mssql_query( "SELECT plid, nopl FROM packlist WHERE whid =
'" . $wh->whid . "'";
while( $pl = mssql_fetch_object( $result ) )
{
$result = mssql_query( "SELECT qty FROM packlistnmat WHERE plid =
'" . $pl->plid . "'";
while( $pln = mssql_fetch_object( $result ) )
{
echo "Stock from " . $wh->whcode . " AND Packing List number " .
$pl->plid . " = " . $pln->qty;
}
}
}
?>
my focus is in nested query, then i can call each field from the query
(SELECT whid, whcode...) in sub query.
thanks,
aCe

  Réponse avec citation
Vieux 22/09/2007, 16h00   #2
Dan Guzman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP code to Stored Procedure

> i need to convert these simple PHP code into stored procedure :

I don't know PHP but you can JOIN the related tables and encapsulate the
query in a stored procedure like the untested example below. You'll often
get best performance by joining related tables on the back-end rather than
performing for-each processing in application code.

CREATE PROCECURE dbo.usp_GetPackingLists
AS
SELECT
w.whcode,
pl.plid,
pln.qty
FROM dbo.warehouse AS w
JOIN packlist AS pl ON w.whid = pl.whid
JOIN packlistnmat AS pln ON pln.plid = pl.plid
GO

<?php
$result = mssql_query( "EXEC dbo.usp_GetPackingLists" );
while( $wh = mssql_fetch_object( $result ) )
{
echo "Stock from " . $wh->whcode . " AND Packing List number " .
$pl->plid . " = " . $pln->qty;
}
?>

--
Hope this s.

Dan Guzman
SQL Server MVP



"aCe" <acerahmat@gmail.com> wrote in message
news:1190444269.094724.14270@57g2000hsv.googlegrou ps.com...
> hi all,
> i need to convert these simple PHP code into stored procedure :
> <?php
> $result = mssql_query( "SELECT whid, whcode FROM warehouse" );
> while( $wh = mssql_fetch_object( $result ) )
> {
> $result = mssql_query( "SELECT plid, nopl FROM packlist WHERE whid =
> '" . $wh->whid . "'";
> while( $pl = mssql_fetch_object( $result ) )
> {
> $result = mssql_query( "SELECT qty FROM packlistnmat WHERE plid =
> '" . $pl->plid . "'";
> while( $pln = mssql_fetch_object( $result ) )
> {
> echo "Stock from " . $wh->whcode . " AND Packing List number " .
> $pl->plid . " = " . $pln->qty;
> }
> }
> }
> ?>
> my focus is in nested query, then i can call each field from the query
> (SELECT whid, whcode...) in sub query.
> thanks,
> aCe
>


  Réponse avec citation
Vieux 24/09/2007, 06h16   #3
aCe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP code to Stored Procedure

On Sep 22, 9:00 pm, "Dan Guzman" <guzma...@nospam-
online.sbcglobal.net> wrote:
> > i need to convert these simple PHP code into stored procedure :

>
> I don't know PHP but you can JOIN the related tables and encapsulate the
> query in a stored procedure like the untested example below. You'll often
> get best performance by joining related tables on the back-end rather than
> performing for-each processing in application code.
>
> CREATE PROCECURE dbo.usp_GetPackingLists
> AS
> SELECT
> w.whcode,
> pl.plid,
> pln.qty
> FROM dbo.warehouse AS w
> JOIN packlist AS pl ON w.whid = pl.whid
> JOIN packlistnmat AS pln ON pln.plid = pl.plid
> GO
>
> <?php
> $result = mssql_query( "EXEC dbo.usp_GetPackingLists" );
> while( $wh = mssql_fetch_object( $result ) )
> {
> echo "Stock from " . $wh->whcode . " AND Packing List number " .
> $pl->plid . " = " . $pln->qty;}
>
> ?>
>
> --
> Hope this s.
>
> Dan Guzman
> SQL Server MVP
>
> "aCe" <acerah...@gmail.com> wrote in message
>
> news:1190444269.094724.14270@57g2000hsv.googlegrou ps.com...
>
> > hi all,
> > i need to convert these simple PHP code into stored procedure :
> > <?php
> > $result = mssql_query( "SELECT whid, whcode FROM warehouse" );
> > while( $wh = mssql_fetch_object( $result ) )
> > {
> > $result = mssql_query( "SELECT plid, nopl FROM packlist WHERE whid =
> > '" . $wh->whid . "'";
> > while( $pl = mssql_fetch_object( $result ) )
> > {
> > $result = mssql_query( "SELECT qty FROM packlistnmat WHERE plid =
> > '" . $pl->plid . "'";
> > while( $pln = mssql_fetch_object( $result ) )
> > {
> > echo "Stock from " . $wh->whcode . " AND Packing List number " .
> > $pl->plid . " = " . $pln->qty;
> > }
> > }
> > }
> > ?>
> > my focus is in nested query, then i can call each field from the query
> > (SELECT whid, whcode...) in sub query.
> > thanks,
> > aCe


thanks for your reply Dan Guzman.
but my query more complex than above.
coz i'm a newby in MSSQL, i need to optimize my query using stored
procedure.

can me further more, thx before...

  Réponse avec citation
Vieux 24/09/2007, 17h29   #4
Ed Murphy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP code to Stored Procedure

aCe wrote:

> thanks for your reply Dan Guzman.
> but my query more complex than above.
> coz i'm a newby in MSSQL, i need to optimize my query using stored
> procedure.
>
> can me further more, thx before...


Unless you plan on posting the more complex query, I doubt he
can. The telepathic version of MSSQL is still about five years
away from RTM.

(joke stolen from the MAS 90 support forums, obviously can be
applied to any software you like)
  Réponse avec citation
Vieux 25/09/2007, 03h43   #5
Dan Guzman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP code to Stored Procedure

> thanks for your reply Dan Guzman.
> but my query more complex than above.
> coz i'm a newby in MSSQL, i need to optimize my query using stored
> procedure.


Do you have another query? I included the stored procedure code in my
response based on the queries and code you provided. If you are having
trouble extending the solution, we'll need more information to .


--
Hope this s.

Dan Guzman
SQL Server MVP

"aCe" <acerahmat@gmail.com> wrote in message
news:1190607404.896418.244680@19g2000hsx.googlegro ups.com...
> On Sep 22, 9:00 pm, "Dan Guzman" <guzma...@nospam-
> online.sbcglobal.net> wrote:
>> > i need to convert these simple PHP code into stored procedure :

>>
>> I don't know PHP but you can JOIN the related tables and encapsulate the
>> query in a stored procedure like the untested example below. You'll
>> often
>> get best performance by joining related tables on the back-end rather
>> than
>> performing for-each processing in application code.
>>
>> CREATE PROCECURE dbo.usp_GetPackingLists
>> AS
>> SELECT
>> w.whcode,
>> pl.plid,
>> pln.qty
>> FROM dbo.warehouse AS w
>> JOIN packlist AS pl ON w.whid = pl.whid
>> JOIN packlistnmat AS pln ON pln.plid = pl.plid
>> GO
>>
>> <?php
>> $result = mssql_query( "EXEC dbo.usp_GetPackingLists" );
>> while( $wh = mssql_fetch_object( $result ) )
>> {
>> echo "Stock from " . $wh->whcode . " AND Packing List number " .
>> $pl->plid . " = " . $pln->qty;}
>>
>> ?>
>>
>> --
>> Hope this s.
>>
>> Dan Guzman
>> SQL Server MVP
>>
>> "aCe" <acerah...@gmail.com> wrote in message
>>
>> news:1190444269.094724.14270@57g2000hsv.googlegrou ps.com...
>>
>> > hi all,
>> > i need to convert these simple PHP code into stored procedure :
>> > <?php
>> > $result = mssql_query( "SELECT whid, whcode FROM warehouse" );
>> > while( $wh = mssql_fetch_object( $result ) )
>> > {
>> > $result = mssql_query( "SELECT plid, nopl FROM packlist WHERE whid =
>> > '" . $wh->whid . "'";
>> > while( $pl = mssql_fetch_object( $result ) )
>> > {
>> > $result = mssql_query( "SELECT qty FROM packlistnmat WHERE plid =
>> > '" . $pl->plid . "'";
>> > while( $pln = mssql_fetch_object( $result ) )
>> > {
>> > echo "Stock from " . $wh->whcode . " AND Packing List number " .
>> > $pl->plid . " = " . $pln->qty;
>> > }
>> > }
>> > }
>> > ?>
>> > my focus is in nested query, then i can call each field from the query
>> > (SELECT whid, whcode...) in sub query.
>> > thanks,
>> > aCe

>
> thanks for your reply Dan Guzman.
> but my query more complex than above.
> coz i'm a newby in MSSQL, i need to optimize my query using stored
> procedure.
>
> can me further more, thx before...
>


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h57.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,83166 seconds with 13 queries