topic
stringlengths
1
63
text
stringlengths
1
577k
ADO RecordSet: Working locally without connecting to Server
Please see the post of Mr James Bott here <!-- l --><a class="postlink-local" href="http://forums.fivetechsupport.com/viewtopic.php?f=3&t=26787&p=149225&hilit=persisting+data#p149225">viewtopic.php?f=3&t=26787&p=149225&hilit=persisting+data#p149225</a><!-- l --> Please also see MSDN Article about Persisting recordsets on local disk [url:2m3m1qmi]http&#58;//msdn&#46;microsoft&#46;com/en-us/library/windows/desktop/ms675273(v=vs&#46;85)&#46;aspx[/url:2m3m1qmi] We can read recordset(s) from a remote server, save them locally and disconnect from the server. We can continue to work with the saved recordset(s) and if we make any modifications we can upload the modifications to the Server, when we next connect to server. This feature is useful in remote locations where connectivity to main server is not reliable and need for update data is minimal. This example shows how to use this feature. Experts in ADO who are wellversed with this feature need to read no further. This post is intended for starters of ADO and those who are not familiar with this feature. This example does not use the FW_ ADO functions and users without these functions also can test this example. (This example uses only FW_CreateMDB function. If you do not have that function, you may use an alternative or use an exsisting MDB) This example 1. Creates a new MDB with a Table 2. Connects to MDB, Opens the table in a recordset and displays in browse 3. Saves the recordset locally. closes connection and renakes MDB as MDD. This is to sumulate non-availability of the server. 4.and 5: Uses the local recordset to edit and add records locally 6. Renaems MDD to MDB, Connects to Database and attaches the connection object to our local recordset Then all changes in the local recordset are UPLOADED to the Server. 7. View the table on the server to confirm uploading all changes. Please compile the program as it is and un in any folder you like. For each step the program explains the stage of the program. It is better you keep the source code open and watch the same along with each step executed by the program. [code=fw:2m3m1qmi]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #B900B9;">/*<br />*<br />*  AdoSave.prg<br />*  Aug 02-2013 12:12 AM<br />*<br />*/</span><br /><br /><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"FiveWin.Ch"</span><br /><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"adodef.ch"</span><br /><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"xbrowse.ch"</span><br /><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"hbcompat.ch"</span><br /><br /><span style="color: #00C800;">static</span> cPath, cMdb, cBak, cDat, cStr<br /><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><br /><span style="color: #00C800;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> oCn, oRs<br /><br />   SET DATE ITALIAN<br />   SET CENTURY <span style="color: #0000ff;">ON</span><br />   XbrNumFormat<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">'A'</span>, .t. <span style="color: #000000;">&#41;</span><br />   SetGetColorFocus<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   <span style="color: #B900B9;">//</span><br />   cPath    := cFilePath<span style="color: #000000;">&#40;</span> ExeName<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><br />   cMdb     := <span style="color: #ff0000;">"tutor02.mdb"</span><br />   cBak     := cFileSetExt<span style="color: #000000;">&#40;</span> cMdb, <span style="color: #ff0000;">"mdd"</span> <span style="color: #000000;">&#41;</span><br />   cDat     := cFileSetExt<span style="color: #000000;">&#40;</span> cMdb, <span style="color: #ff0000;">"dat"</span> <span style="color: #000000;">&#41;</span><br />   cStr     := <span style="color: #ff0000;">"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="</span> + cPath + cMdb + <span style="color: #ff0000;">";"</span><br /><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><span style="color: #B900B9;">// STEP-1: Create New Database TUTOR02.MDB and create a table DLYCLN</span><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Step-1"</span> + CRLF + <span style="color: #ff0000;">"Create new mdb database: "</span> + cMdb <span style="color: #000000;">&#41;</span><br />   CreateNewDatabase<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Data base '"</span> + cMdb + <span style="color: #ff0000;">"' and table 'DLYCLN' created."</span> <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><span style="color: #B900B9;">// STEP-2: OPEN TABLE "DLYCLN" in the database and show contents</span><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Step-2"</span> + CRLF + <span style="color: #ff0000;">"Opening recordset of DLYCLN table"</span> <span style="color: #000000;">&#41;</span><br />   oRs      := CreateObject<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"ADODB.RecordSet"</span> <span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">CursorLocation</span>   := adUseClient<br />   oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"DLYCLN"</span>, cStr, adOpenStatic, adLockBatchOptimistic, adCmdTable <span style="color: #000000;">&#41;</span><br />   xbrowser oRs <span style="color: #0000ff;">TITLE</span> cMdb + <span style="color: #ff0000;">":DLYCLN"</span><br /><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><span style="color: #B900B9;">// STEP-3: SAVE RECORDSET TO LOCAL DISK, CLOSE RECORDSET AND CONNECTION TO DATABASE</span><br /><span style="color: #B900B9;">//         RENAME THE MDB AS MDD, SO THAT WE CAN NOT CONNECT TO THE DATABASE</span><br /><span style="color: #B900B9;">//         THIS IS TO SIMULATE NON-AVAILABILITY OF SERVER</span><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Step-3: Saving RecordSet Locally as "</span> + cDat + CRLF + <span style="color: #ff0000;">"Syntax: oRs:Save( cDat, 0 )"</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">if</span> File<span style="color: #000000;">&#40;</span> cDat <span style="color: #000000;">&#41;</span>; FErase<span style="color: #000000;">&#40;</span> cDat <span style="color: #000000;">&#41;</span>; <span style="color: #00C800;">endif</span><br />   oRs:<span style="color: #000000;">Save</span><span style="color: #000000;">&#40;</span> cDat, <span style="color: #000000;">0</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Record Set saved as: "</span> + cDat <span style="color: #000000;">&#41;</span><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Closing Connection"</span> <span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   oRs := <span style="color: #00C800;">nil</span><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Renaming "</span> + cMdb + <span style="color: #ff0000;">" as "</span> + cBak + CRLF + ;<br />      <span style="color: #ff0000;">"This is equivalent to not having connection with Server"</span> <span style="color: #000000;">&#41;</span><br />   ? FRename<span style="color: #000000;">&#40;</span> cMdb, cBak <span style="color: #000000;">&#41;</span><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Now we can not connect to Database "</span> + cMdb <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><span style="color: #B900B9;">// STEP-4: OPEN LOCALLY SAVED FILE AS RECORDSET WITHOUT CONNECTING TO ANY DATABASE</span><br /><span style="color: #B900B9;">//         AND EDIT THE TABLE IN XBROWSE AND SAVE CHANGES LOCALLY</span><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Step-4"</span> + CRLF + <span style="color: #ff0000;">"Now we open locally saved RecSet without any connection"</span> + CRLF + ;<br />            <span style="color: #ff0000;">"You may edit any data inline"</span> <span style="color: #000000;">&#41;</span><br />   oRs      := CreateObject<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"ADODB.RecordSet"</span> <span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">CursorLocation</span>   := adUseClient<br />#ifdef __XHARBOUR__<br />   oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span> cDat, OleDefaultArg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, adOpenStatic, adLockBatchOptimistic, adCmdFile <span style="color: #000000;">&#41;</span><br />#else<br />   oRs:<span style="color: #000000;">Source</span>     := cDat<br />   oRs:<span style="color: #000000;">LockType</span>   := adLockBatchOptimistic<br />   oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />#endif<br /><br />   xbrowser oRs <span style="color: #0000ff;">TITLE</span> <span style="color: #ff0000;">"localcopy:DLYCLN (fastedit mode)"</span> FASTEDIT  SETUP ;<br />      <span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">bSaveData</span> := <span style="color: #000000;">&#123;</span> || .t. <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">Save</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><span style="color: #B900B9;">// STEP-5: RE-OPEN LOCALLY SAVED FILE AS RECORDSET WITHOUT CONNECTING TO ANY DATABASE</span><br /><span style="color: #B900B9;">//         ADD TWO NEW ROWS</span><br /><span style="color: #B900B9;">//         AND EDIT THE TABLE IN XBROWSE AND SAVE CHANGES LOCALLY</span><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Step-5: Saved and closed. Reopening Again"</span> <span style="color: #000000;">&#41;</span><br /><br />   oRs      := CreateObject<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"ADODB.RecordSet"</span> <span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">CursorLocation</span>   := adUseClient<br />#ifdef __XHARBOUR__<br />   oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span> cDat, OleDefaultArg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, adOpenStatic, adLockBatchOptimistic, adCmdFile <span style="color: #000000;">&#41;</span><br />#else<br />   oRs:<span style="color: #000000;">Source</span>     := cDat<br />   oRs:<span style="color: #000000;">LockType</span>   := adLockBatchOptimistic<br />   oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />#endif<br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Adding two new rows to the local copy"</span> <span style="color: #000000;">&#41;</span><br /><br />   oRs:<span style="color: #000000;">AddNew</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #ff0000;">"WDAY"</span>, <span style="color: #ff0000;">"COLN"</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #ff0000;">"FriDay"</span>, <span style="color: #000000;">800</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">AddNew</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #ff0000;">"WDAY"</span>, <span style="color: #ff0000;">"COLN"</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #ff0000;">"SaturDay"</span>, <span style="color: #000000;">800</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br /><br />   xbrowser oRs <span style="color: #0000ff;">TITLE</span> <span style="color: #ff0000;">"localcopy:DLYCLN (fastedit mode)"</span>  FASTEDIT  SETUP ;<br />      <span style="color: #000000;">&#40;</span> oBrw:<span style="color: #000000;">bSaveData</span> := <span style="color: #000000;">&#123;</span> || .t. <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">Save</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><span style="color: #B900B9;">// STEP-6: NOW WE RENAME THE MDD AS MDB. THE DATABASE IS AVAILABLE TO CONNECT</span><br /><span style="color: #B900B9;">//         WE CONNECT TO THE DATABASE AND ATTACH OUR LOCAL RECSET TO THE CONNECTION</span><br /><span style="color: #B900B9;">//         UPLOAD LOCAL CHANGES TO THE DATABASE, DELETE LOCAL FILE</span><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Step-6"</span> + CRLF + <span style="color: #ff0000;">"Now we rename "</span> + cBak + <span style="color: #ff0000;">" to "</span> + cMdb + CRLF + ;<br />      <span style="color: #ff0000;">"Connect to Database and Upload local changes to Main DataBase"</span> <span style="color: #000000;">&#41;</span><br /><br />   ? FRename<span style="color: #000000;">&#40;</span> cBak, cMdb <span style="color: #000000;">&#41;</span><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> cMdb + <span style="color: #ff0000;">" now available. Connecting"</span> <span style="color: #000000;">&#41;</span><br />   oCn   := CreateObject<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"ADODB.Connection"</span> <span style="color: #000000;">&#41;</span><br />   oCn:<span style="color: #000000;">CursorLocation</span>   := adUseClient<br />   oCn:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span> cStr <span style="color: #000000;">&#41;</span><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Connected to Database. Connecting Local RecSet to Database"</span> + CRLF + ;<br />            <span style="color: #ff0000;">"Syntax: oRs:ActiveConnection := oCn"</span> <span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">ActiveConnection</span> := oCn<br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Now our recordset is connected to database"</span> + CRLF + ;<br />            <span style="color: #ff0000;">"We shall upload changes. Syntax: oRs:UpdateBatch()"</span> <span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">UpdateBatch</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Uploaded. Now we close RecSet & Connection"</span> <span style="color: #000000;">&#41;</span><br /><br />   oRs:<span style="color: #000000;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   oCn:<span style="color: #000000;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   oRs := oCn := <span style="color: #00C800;">nil</span><br />   ? FErase<span style="color: #000000;">&#40;</span> cDat <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><span style="color: #B900B9;">// STEP-7: NOW WE CONNECT TO DATABASE NORMALLY, OPEN TABLE IN THE DATABASE</span><br /><span style="color: #B900B9;">//         TO CONFIRM THAT ALL CHANGES ARE PRESENT IN THE DATABASE</span><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Step-7: Now we open the table in the database and"</span> + CRLF + <span style="color: #ff0000;">"verify if all changes are uploaded"</span> <span style="color: #000000;">&#41;</span><br /><br />   oRs   := CreateObject<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"ADODB.RecordSet"</span> <span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">CursorLocation</span>   := adUseClient<br />   oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"DLYCLN"</span>, cStr, adOpenStatic, adLockBatchOptimistic, adCmdTable <span style="color: #000000;">&#41;</span><br />   xbrowser oRs<br /><br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"All Done."</span> + CRLF +  <span style="color: #ff0000;">"Cleaning Up"</span> <span style="color: #000000;">&#41;</span><br />   oRs:<span style="color: #000000;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   oRs   := <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><br /><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /><br /><span style="color: #00C800;">static</span> <span style="color: #00C800;">function</span> CreateNewDatabase<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> cSql, oCn, n<br />   <span style="color: #00C800;">local</span> aData := <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#123;</span> <span style="color: #ff0000;">"MonDay"</span>, <span style="color: #000000;">40</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #ff0000;">"TuesDay"</span>, <span style="color: #000000;">50</span> <span style="color: #000000;">&#125;</span>, <span style="color: #000000;">&#123;</span> <span style="color: #ff0000;">"WednesDay"</span>, <span style="color: #000000;">60</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span><br /><br />   <span style="color: #00C800;">if</span> File<span style="color: #000000;">&#40;</span> cMdb <span style="color: #000000;">&#41;</span><br />      FErase<span style="color: #000000;">&#40;</span> cMdb <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">endif</span><br />   <span style="color: #00C800;">if</span> File<span style="color: #000000;">&#40;</span> cBak <span style="color: #000000;">&#41;</span><br />      FErase<span style="color: #000000;">&#40;</span> cBak <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">endif</span><br />   FW_CreateMDB<span style="color: #000000;">&#40;</span> cMdb <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #0000ff;">TEXT</span> INTO cSql<br />   CREATE TABLE DLYCLN <span style="color: #000000;">&#40;</span><br />   <span style="color: #0000ff;">ID</span> AUTOINCREMENT PRIMARY KEY,<br />   WDAY VARCHAR<span style="color: #000000;">&#40;</span><span style="color: #000000;">20</span><span style="color: #000000;">&#41;</span>,<br />   COLN MONEY<br />   <span style="color: #000000;">&#41;</span><br />   ENDTEXT<br /><br />   oCn   := CreateObject<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"ADODB.Connection"</span> <span style="color: #000000;">&#41;</span><br />   oCn:<span style="color: #000000;">CursorLocation</span>   := adUseClient<br />   oCn:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span> cStr <span style="color: #000000;">&#41;</span><br />   oCn:<span style="color: #000000;">Execute</span><span style="color: #000000;">&#40;</span> cSql <span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">for</span> n := <span style="color: #000000;">1</span> <span style="color: #0000ff;">to</span> Len<span style="color: #000000;">&#40;</span> aData <span style="color: #000000;">&#41;</span><br />      cSql  := <span style="color: #ff0000;">"INSERT INTO DLYCLN ( WDAY, COLN ) VALUES ( '"</span> + ;<br />               aData<span style="color: #000000;">&#91;</span> n, <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> + <span style="color: #ff0000;">"',"</span> + cValToChar<span style="color: #000000;">&#40;</span> aData<span style="color: #000000;">&#91;</span> n, <span style="color: #000000;">2</span> <span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">" )"</span><br />      oCn:<span style="color: #000000;">Execute</span><span style="color: #000000;">&#40;</span> cSql <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">next</span> n<br />   oCn:<span style="color: #000000;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />   oCn   := <span style="color: #00C800;">nil</span><br /><br /><span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br /><span style="color: #B900B9;">//----------------------------------------------------------------------------//</span><br /> </div>[/code:2m3m1qmi]
ADO RecordSet: Working locally without connecting to Server
Mr. Rao: Thanks a lot for your aportation, with the RecordSet's GetRows() method can you get the same result? Regards
ADO RecordSet: Working locally without connecting to Server
[quote="Armando":1zw7te9u]Mr. Rao: Thanks a lot for your aportation, with the RecordSet's GetRows() method can you get the same result? Regards[/quote:1zw7te9u] With GetRows() method you can read the recordset into an array. Agreed that you can do anything with the array locally. You can make modifications too. When you reconnect, how do you upload the changes? You need to develop your own logic to identify (1) new rows inserted, (2) rows deleted and (3) rows modified and the columns in the rows that are modified. Then you need to develop your own logic to add those new lines, delete those rows and update the specific modified columns of the modified rows. Is all the trouble worth it? And even you do it, can you do it optimally and without errrors at all? With the persistent recordset, you need to do only two operations: oRs:ActiveConnection := <justopened connection object> oRs:UpdateBatch() Ofcourse you need to use TRY..CATCH for all ADO methods. You may say that you do not want to modify the data but only want for reference. The why not GetRows() enough? Yes but only for that session. When the user closes the application and reopens, the information in the array is lost. Till you connect to the Server you can not get the info. In the case of persistent recordset what we do is : When the user starts the program Check if connection to server is available. (i) If avaliable Synchronize local recordset with Server ( Push and Pull ) (ii) If not, continue with the local recordset
ADO RecordSet: Working locally without connecting to Server
Let me add. Handling recordsets is more cumbersome than RDD and TData(Base)
ADO RecordSet: Working locally without connecting to Server
Mr. Rao: Thank for your comments. Regards
ADO RecordSet: Working locally without connecting to Server
Mr. Rao: Thanks for your works, I have a problem with MsgInfo( "Renaming " + cMdb + " as " + cBak + CRLF + ; "This is equivalent to not having connection with Server" ) ? FRename( cMdb, cBak ) frename returns -1 , this is because cMdb is still open Regards Maurizio
ADO RecordSet: Working locally without connecting to Server
[quote:2wj2y3g8]? FRename( cMdb, cBak ) frename returns -1 , this is because cMdb is still open [/quote:2wj2y3g8] If it returns -1, then renaming was not successful for whatever reason and one of such reasons could be that the mdb is not fully closed and released. If you execute the code I posted without any changes, the connection should be closed and the renaming should be successful. Though I made this sample with access for easy testing, this principle can be tested on networks or over internet by disconnecting the net connection.
ADO RecordSet: Working locally without connecting to Server
Mr. Rao with the FWH 13.07 revised build it works Thanks Maurizio
ADO RecordSets - Change SQL & Con at Runtime
At times it may be necessary to change the data of a Recordset with totally different data from the same or different tables and even from a different connection. One way is to read the new data into a new recordset and swap with the present recordset. It is much easier to read the different data into the same recordset in this manner: [code=fw:12u9yqma]<div class="fw" id="{CB}" style="font-family: monospace;"><br />oRs:<span style="color: #000000;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />oRs:<span style="color: #000000;">Source</span> := cNewSQL<br />oRs:<span style="color: #000000;">ActiveConnection</span> := oNewConObject<br />oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /> </div>[/code:12u9yqma] If this change is made while the recordset is being browsed, the Browse should be able to handle the change smoothly, which was not possible till FWH18.04. FWH 18.05 handles the change smoothly, as in this sample: [code=fw:12u9yqma]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00D7D7;">#include</span> <span style="color: #ff0000;">"fivewin.ch"</span><br /><br /><span style="color: #00C800;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br />   <span style="color: #00C800;">local</span> oCnMDB, oCnDBF, oCnFWH, oRs<br />   <span style="color: #00C800;">local</span> cSqlMDB, cSqlDBF, cSqlFWH<br />   <span style="color: #00C800;">local</span> oDlg, oBrw<br /><br />   oCnMDB   := FW_OpenAdoConnection<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"c:<span style="color: #000000;">\f</span>wh<span style="color: #000000;">\s</span>amples<span style="color: #000000;">\x</span>brtest.mdb"</span> <span style="color: #000000;">&#41;</span><br />   oCnDBF   := FW_OpenAdoConnection<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"c:<span style="color: #000000;">\f</span>wh<span style="color: #000000;">\s</span>amples<span style="color: #000000;">\"</span> )   <br />   oCnFWH   := FW_DemoDB( "</span>ADO<span style="color: #ff0000;">" )<br /><br />   cSqlMDB  := "</span><span style="color: #0000ff;">SELECT</span> <span style="color: #0000ff;">ID</span>,FIRST,CITY,SALARY <span style="color: #0000ff;">FROM</span> CUSTOMER<span style="color: #ff0000;">"<br />   cSqlDBF  := "</span><span style="color: #0000ff;">SELECT</span> * <span style="color: #0000ff;">FROM</span> STATES<span style="color: #ff0000;">"<br />   cSqlFWH  := "</span><span style="color: #0000ff;">SELECT</span> * <span style="color: #0000ff;">FROM</span> annual<span style="color: #ff0000;">"<br /><br />   oRs      := FW_OpenRecordSet( oCnMDB, cSqlMDB )<br /><br />   DEFINE DIALOG oDlg SIZE 700,400 PIXEL TRUEPIXEL<br /><br />   @ 60, 20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;<br />      DATASOURCE oRs AUTOCOLS ;<br />      CELL LINES NOBORDER<br />   oBrw:CreateFromCode()<br /><br />   @ 10, 20 BTNBMP PROMPT "</span>ADO-MDB<span style="color: #ff0000;">" SIZE 100,30 PIXEL OF oDlg FLAT ;<br />      ACTION ReadNewData( oBrw, cSqlMDB, oCnMDB )<br /><br />   @ 10,140 BTNBMP PROMPT "</span>ADO-DBF<span style="color: #ff0000;">" SIZE 100,30 PIXEL OF oDlg FLAT ;<br />      ACTION ReadNewData( oBrw, cSqlDBF, oCnDBF )<br /><br />   @ 10,260 BTNBMP PROMPT "</span>ADO-MYSQL<span style="color: #ff0000;">" SIZE 100,30 PIXEL OF oDlg FLAT ;<br />      ACTION ReadNewData( oBrw, cSqlFWH, oCnFWH )<br /><br />   ACTIVATE DIALOG oDlg CENTERED ON INIT oBrw:SetFocus()<br /><br />   oCnMDB:Close()<br />   oCnDBF:Close()<br />   oCnFWH:Close()<br /><br />return nil<br /><br />function ReadNewData( oBrw, cSql, oCn )<br /><br />   WITH OBJECT oBrw:oRs<br />      :Close()<br />      :Source           := cSql<br />      :ActiveConnection := oCn<br />      CursorWait()<br />      :Open()<br />   END<br />   WITH OBJECT oBrw<br />      :SetADO( oBrw:oRs, .t. )<br />      :SetFocus()<br />   END<br /><br />return nil<br /></span></div>[/code:12u9yqma] [url=https&#58;//imageshack&#46;com/i/pmSKHdLCg:12u9yqma][img:12u9yqma]https&#58;//imageshack&#46;com/a/img922/1616/SKHdLC&#46;gif[/img:12u9yqma][/url:12u9yqma]
ADO RecordSets - Change SQL & Con at Runtime
Very impressive <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) --> Great capabilities for the new FWH 18.05 <!-- s;-) --><img src="{SMILIES_PATH}/icon_wink.gif" alt=";-)" title="Wink" /><!-- s;-) -->
ADO Recordset Methods
Hi guys Where I can find more information about ADO Recordset methods and properties like RecordCount(), fields etc Thanks
ADO Recordset Methods
On MSDN. EMG
ADO Recordset Methods
Thanks Enrico
ADO SQL VISIBILITY
Dear Sir(s) I have one table in sql database. if USER1 is browsing ARTICLE table and make some changes, how to to update/visible USER2 browse with the same change? Something like dbf. when we change records it update to every where. Regards Yunus.
ADO SQL VISIBILITY
You can use: CursorLocation := adUseServer CursorType := adOpenDynamic Pros: Selects without where clause much faster because you dont load immediately all records You'll see new adds deletes changes by others. You will always have the last info version. Cons: Navigation slower and server overload higher Many Dbs do not supported so you might get it through the ODBC OLedb driver. This means all navigation is transformed into queries by the driver itself delaying everything. In Mysql you'll need a column to be used as recno Servers that supported might be better. Never tried adUseServer without a server supporting it.
ADO SQL VISIBILITY
Yunus, As far as I know, there is no way other than redoing the query. EMG
ADO SQL VISIBILITY
Dagia You can put a few well placed oRs:ReQuery() to re-fresh each workstation .. Generally you can place a :ReQuery() between screens which should keep each workstation in sync. .. again, SQL workstation visibility is an art-form and takes a fairly savvy programming imagination to keep them in sync. Rick Lipkin
ADO SQL VISIBILITY
Dear EMG, AHF & RICK LIPKIN Thanks for the valuable information. Thanks & Regards
ADO SQL VISIBILITY
[quote:297kcfmu]SQL workstation visibility is an art-form and takes a fairly savvy programming imagination to keep them in sync.[/quote:297kcfmu] Yes.
ADO SQL VISIBILITY
Severside queries (RecordSet with adUseServer) are *mostly* unidirectional and single pass, used mainly for fast single pass processing. Even this is not generally desirable and may result in wrong results because we lose the benefit of snap-shot query benefits. What we mostly use is RecordSet with adUseClient with either adLockOptimistic or adLockBatchOptimistic. All this is static information as at the time when we executed the query. The recordset does not get updated on its own unless we explicitly execute oRs:Requery() or in suitable cases oRs:ReSync(). With a view to keep our browse uptodate, we can not keep executing oRs:Requery() or oRs:Resync() continuously. What Mr Rick refers to is when to do this. XBrowse and TDataRow do this to some extent. That is when a user attempts to edit a row, either by inline edit or by calling oBrw:Edit() or EditSource(), the row is resynced first and then offered to edit. In other words, the user sees the latest data before he starts editing.
ADO SQL VISIBILITY
Mr Rao, I think like in ADORDD the main problem is with additions because deletions or changes are always catched when we try to update. In ADORDD this is only a problem working without true locks because otherwise for ex. the order will be locked and no additions are possible during a WS edition or transaction like in a normal DBF execution. To control if we need to refresh the recordset because of additions we are studying this possibility: 1) RDD area array element keeping datetime value of the last refresh of the recordset 2) A SQL table NEEDREFRESH with fields: TABLE = TABLENAME DATETIME = DATE TIME ADD NEW RECORD 3) Every time a new addition is made its registered (add or replaced) in NEEDREFRESH with datetime of addition and table name. This can be done directly from ADORDD code or through a trigger or procedure in the server. We have to decide. 4) Every time any replace, delete, addnew takes place the ADORDD first looks in NEEDREFRESH for the table 5) If the datetime in NEEDREFRESH table is newer than the RDD area array element with the datetime last refresh of our recordset we refresh it again resetting the RDD area array element. One can install a procedure at the server to run at certain hours when no one its connected to clean up this table. Its a trade off between integrity and speed. This is only primary proposal study phase and at the end we might go other way. We will start working it middle August. Nevertheless I would like very much to have you opinion.
ADO SQL VISIBILITY
Mr Antonio You wanted a quick method to know if other users added new records after current user opened the recordset. This discussion is confined to direct tables (not queries) opened using adUseClient. If the table has a primary-key and value of primary-key inserted is always greater than the previously inserted key ( autoincrement or similar) then: if the result of "select max(primarykeycolumn) from thetable" is greater than the maximum value of primary key in our recordset (we can keep this info somewhere in memory) it means other users added some rows. Then we issue oRs:Requery() and reposition our record pointer again at the previous position. "select max(primarykey)" is always highly optimized and fast. If the table does not have a primary key, then leave it. The programmer anyway will face lots of problems and learn by mistakes. Anyway for small tables we may compare COUNT(*) with oRs:RecordCount() and decide, though it is slow and not foolproof. When opening a table it is easy for us to identify the primary key and also if it is auto-increment. SQLSERVER specific: In case the table has auto-increment primary key, we can use "SELECT IDENT_CURRENT(‘tablename’)" to know the last primary key value inserted. This is faster even than Max(PrimaryKey). Some programmers may use rowVersion or timestamp fields. It is possible to identify such fields while opening the table. In such cases comparing the max() values indicates activity by other users. Next question is how frequently we need to keep checking for other users' inserts. We can't keep checking continuously. If the reocrdset is ordered on the primary key, it may be enough to check when (i) DBGOBOTTOM() and (ii) when DBSKIP( +n ) hits EOF. In other cases we may need to do it with every SKIP() but this may slowdown the skips. You may please test it on large tables and decide.
ADO SQL VISIBILITY
This is just for academic interest. From version 2005, MS SQLSERVER introduced a notification feature. Instead of client querying the server frequently for any changes in the status, a notification queue can be created and server notifies the clients with subscription whenever the change happens. Client retrieves the notifications with "RECEIVE * FROM <quename>". This reduces the round-trip overhead. I myself never had any occasion to use this feature.
ADO SQL VISIBILITY
Mr Rao, [quote:3ndie2mh]"select max(primarykey)" is always highly optimized and fast.[/quote:3ndie2mh] Adordd its working like that but I found at least with Mysql that its taking too long. If you try to use it for instances like a reccount() the browses begin to be very slow on a WAN even with tables of 50.000 recs. I agree that its a must to have a primaryey as unique autoinc value. COUNT() its not reliable and we should forget it. ADORRD recno its based on a primarykey and it can happen that count returns 20 rows but select max() returns 35. So adordd can only use select max otherwise we could have Lastrec() returning 20 and recno 35! [quote:3ndie2mh]Next question is how frequently we need to keep checking for other users' inserts. We can't keep checking continuously. If the reocrdset is ordered on the primary key, it may be enough to check when (i) DBGOBOTTOM() and (ii) when DBSKIP( +n ) hits EOF.[/quote:3ndie2mh] I was thinking in checking it before any update, addnew, delete. But dbgobott its good idea as a refresh trigger although it might not be ordered by the primarykey. To test it on every skip is unfeasible with select max() it simply takes too long. Another option Im study is to have a TRIGGER for every table primarykey field used as recno. Something like this: CREATE TRIGGER cname ON cTable BEFORE INSERT ... Where it saves in a table like: TLASTREC TABLENAME C 30 MAXKEY N 10 0 The MAX value of the primarykey. This table will be the size of n tables in the database so pretty small always. Querying it even with skip should be lightning fast. Concerning MSSQL QUEUES I didnt never tried it but I would like a solution that would be the same for every SQL engine. What do you think about this? Thanks
ADO SQL VISIBILITY
Mr Antonio I agree that COUNT(* or any field) is the slowest on every RDMS. Except for small tables or otherwise optimize queries yielding small subsets, no body uses count(). Because primary-key is indexed max(primary-key) should be faster but not instantaneous like the query I suggested for sql-server. I go by your tests about the acceptability or otherwise of this approach from speed point of view. Can you please try this query for reliability and speed? SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'DatabaseName' AND TABLE_NAME = 'TableName'; Better we do not interfere with triggers etc. Better to leave it to their database programmers.
ADO SQL VISIBILITY
Mr Rao, [quote:330cfz4w]Better we do not interfere with triggers etc. Better to leave it to their database programmers.[/quote:330cfz4w] True I know we shouldnt do it. [code=fw:330cfz4w]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #0000ff;">SELECT</span> `AUTO_INCREMENT` <span style="color: #0000ff;">FROM</span> INFORMATION_SCHEMA.TABLES<br /><span style="color: #0000ff;">WHERE</span> TABLE_SCHEMA = <span style="color: #ff0000;">'DatabaseName'</span> AND TABLE_NAME = <span style="color: #ff0000;">'TableName'</span>;</div>[/code:330cfz4w] This might be it! Ill keep you posted. Is it supported by all engines ?
ADO SQL VISIBILITY
No This is for MySql and I did not use it. For MsSql I advised another query. Let us first provide optimal performance for at least two popular servers. Let's keep exploring.
ADO SQL VISIBILITY
Mr Rao, It works ok I need further testing. How can I check the size of the schema table being queried ? Is it there only the max autoinc of each table ?
ADO SQL VISIBILITY
SELECT * FROM INFORMATION_SCHEMA.TABLES
ADO SQL VISIBILITY
Mr Antonio Please try this on different databases and see if this works. [code=fw:1csdtyl2]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00C800;">function</span> LastAutoIncID<span style="color: #000000;">&#40;</span> cTable, cPrimaryKey, oCn <span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #00C800;">local</span> oRs, nRet<br /><br />&nbsp; &nbsp;oRs &nbsp; := oCn:<span style="color: #000000;">OpenSchema</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">12</span>, <span style="color: #000000;">&#123;</span> <span style="color: #00C800;">nil</span>, <span style="color: #00C800;">nil</span>, <span style="color: #00C800;">nil</span>, <span style="color: #00C800;">nil</span>, ctable <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;oRs:<span style="color: #000000;">Filter</span> &nbsp;:= <span style="color: #ff0000;">"COLUMN_NAME = '"</span> + cPrimaryKey + <span style="color: #ff0000;">"'"</span><br />&nbsp; &nbsp;nRet &nbsp; &nbsp; &nbsp; &nbsp;:= oRs:<span style="color: #000000;">Fields</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"CARDINALITY"</span> <span style="color: #000000;">&#41;</span>:<span style="color: #000000;">Value</span><br /><br /><span style="color: #00C800;">return</span> nRet<br /> </div>[/code:1csdtyl2] Notes: (1) You need to add error checking later (2) Use this only if AUTOINCREMENT primary key exists Added: This works with MSACCESS, MSSQL and MYSQL
ADO SQL VISIBILITY
[quote="dagiayunus":r49dv00l]Dear Sir(s) I have one table in sql database. if USER1 is browsing ARTICLE table and make some changes, how to to update/visible USER2 browse with the same change? Something like dbf. when we change records it update to every where. Regards Yunus.[/quote:r49dv00l] When we browse a DBF, we see other usres' changes to a row when we "move" to that row. We do not see any changes by other users automatically, without navigating the browse. To get the same effect, while creating the browse, add this line: oBrw:bChange := { || oBrw:oRs:Resync( 1, 2 ), oBrw:RefreshCurrent() } When a user moves browse cursor to any row, he will see the latest values of that row, as modified by other users. In case of DBF, when we refresh the browse, we see all changes to all rows that are visible in the browse window. To get the same effect: oBrw:bOnRefresh := { || oBrw:oRs:Requery() } As we go on things get a bit more complex, which need to learn step by step. Talking about multi-user issues, ADO is more secure in handling multi-user conflicts than DBF.
ADO SQL slow after idle for a while
Hi, I'm using FWH ADO on MariaDB. Everything is working fine. Only one client have a problem on 2 PC's The program is a cash desk. If the products are scanned, everything is fast. If there is no client for 5 minutes, I take 8 seconds to show the product on the screen after scanning. Then everything is working fast again. First I thought that it was the server that when to sleep-mode, but when testing it with an other (older) PC, it keeps being fast. Does anyone know what the problem can be. The PC's are running Windows 10. The server is a Synology NAS with MariaDB on it. Thanks
ADO SQL slow after idle for a while
Hi, Does anyone else have also this problem? I've been testing it and have change some settings in the database-server, but no result. The delay is not very long (0.8s), but the problem is that it is used in a shop with a barcodescanner, and then it is long if they have to wait <!-- s:( --><img src="{SMILIES_PATH}/icon_sad.gif" alt=":(" title="Sad" /><!-- s:( --> I run a simple query [code=fw:s30sb5dc]<div class="fw" id="{CB}" style="font-family: monospace;">otmp = CREATEOBJECT<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"ADODB.Recordset"</span> <span style="color: #000000;">&#41;</span><br />otmp:<span style="color: #000000;">cursortype</span> :=<span style="color: #000000;">1</span><br />otmp:<span style="color: #000000;">cursorlocation</span> :=<span style="color: #000000;">3</span><br />otmp:<span style="color: #000000;">locktype</span> := <span style="color: #000000;">3</span><br />otmp:<span style="color: #000000;">open</span><span style="color: #000000;">&#40;</span>SQLCommando,ADO_SQL_Connectionstring<span style="color: #000000;">&#41;</span><br /> </div>[/code:s30sb5dc] It only lake 0.03s to run, but after waiting a while (1-2minutes) it take 0.8s, and then 0.03s again... I have been change the query_cache_size, but no luck <!-- s:( --><img src="{SMILIES_PATH}/icon_sad.gif" alt=":(" title="Sad" /><!-- s:( --> I have been thinking to run a timer that call a query each 20sec, but I think there must be another solution. The strange thing is that they als have al old XP-PC, and there is no delay, only on the Windows 10 pc's <!-- s:shock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked" /><!-- s:shock: --> I just tried to connect my laptop to the network, and on my PC it also keeps running fine (Windows 10 Pro) <!-- s:shock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked" /><!-- s:shock: --> <!-- s:shock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked" /><!-- s:shock: --> <!-- s:shock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked" /><!-- s:shock: -->
ADO SQL slow after idle for a while
>>> otmp:open(SQLCommando,ADO_SQL_Connectionstring) >>> If you want speed, do not use connection strings, use connection object which is already open.
ADO SQL slow after idle for a while
Thank you, but how can I the run each time a different query to receive arecordsset?
ADO SQL slow after idle for a while
Marc Here is a Sql Server example on how to create a Global Connection (oCn ) .. Once you have made your connection .. just pass oCn instead of your connection string. There are other ways you can do the same thing using the FWAdo wrappers .. Rao can help you there. Rick Lipkin [code=fw:2megjoka]<div class="fw" id="{CB}" style="font-family: monospace;"><br /><span style="color: #00C800;">Local</span> xProvider,xSource,xCatalog,xPassword,cString,oRs<br /><span style="color: #00C800;">Public</span> oCn<br /><br /><br />xPROVIDER := <span style="color: #ff0000;">"SQLOLEDB"</span> &nbsp; &nbsp;<span style="color: #B900B9;">// specific to Sql Server .. ole</span><br />xSOURCE   := <span style="color: #ff0000;">"YourServer"</span><br />xCatalog  := <span style="color: #ff0000;">"YourDatabase"</span><br />xUserId   := <span style="color: #ff0000;">"XXXXXXX"</span><br />xPASSWORD := <span style="color: #ff0000;">"XXXXXXX"</span><br /><br /><br />cString := <span style="color: #ff0000;">'Provider='</span>+xPROVIDER+<span style="color: #ff0000;">';Data Source='</span>+xSOURCE+<span style="color: #ff0000;">';Initial Catalog='</span>+xCATALOG+<span style="color: #ff0000;">';User Id='</span>+xUSERID+<span style="color: #ff0000;">';Password='</span>+xPASSWORD<br /><br /><span style="color: #B900B9;">// global connection string</span><br />oCn := CREATEOBJECT<span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"ADODB.Connection"</span> <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">TRY</span><br />   oCn:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span> cString <span style="color: #000000;">&#41;</span><br />CATCH oErr<br />   Saying := <span style="color: #ff0000;">"Could not open a Global Connection to Database "</span>+xSource<br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> Saying <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">RETURN</span><span style="color: #000000;">&#40;</span>.F.<span style="color: #000000;">&#41;</span><br />END <span style="color: #00C800;">TRY</span><br /><br /><span style="color: #B900B9;">// open a recordset with global connection</span><br />oRs := TOleAuto<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"ADODB.Recordset"</span> <span style="color: #000000;">&#41;</span><br />oRs:<span style="color: #000000;">CursorType</span>     := <span style="color: #000000;">1</span>        <span style="color: #B900B9;">// opendkeyset</span><br />oRs:<span style="color: #000000;">CursorLocation</span> := <span style="color: #000000;">3</span>        <span style="color: #B900B9;">// local cache</span><br />oRs:<span style="color: #000000;">LockType</span>       := <span style="color: #000000;">3</span>        <span style="color: #B900B9;">// lockoportunistic</span><br /><br />cSQL := <span style="color: #ff0000;">"SELECT * from YourTable"</span><br /><br /><span style="color: #00C800;">TRY</span><br />  oRS:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span>cSQL,oCn <span style="color: #000000;">&#41;</span><br />CATCH oErr<br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Error in Opening YourTable )<br />      Return(.f.)<br />END TRY<br /></span></div>[/code:2megjoka]
ADO SQL slow after idle for a while
Rick, Thank you, I will try it.
ADO STORED PROCEDURES
If you are looking for a Sample on how to call a stored procedure on MS-SQL Server with parameters, here is one which may be useful to you [code=fw:pirhx5yi]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #B900B9;">// Trying to initiate the Stored Procedure</span><br />oCmd:=CreateObject<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"ADODB.Command"</span><span style="color: #000000;">&#41;</span><br />oCmd:<span style="color: #000000;">ActiveConnection</span>:=oApp:<span style="color: #000000;">oConnection</span><br />oCmd:<span style="color: #000000;">CommandType</span>:=adCmdStoredProc<br />oCmd:<span style="color: #000000;">CommandText</span>:=<span style="color: #ff0000;">"StockUpDate"</span> &nbsp;<span style="color: #B900B9;">// Strored Procedure Name</span><br /><br /><span style="color: #B900B9;">// Creating Parameters before sending parameters to Stored Procedure</span><br />oParam := oCmd:<span style="color: #000000;">CreateParameter</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"cPartNo"</span>, adChar, adParamInput, <span style="color: #000000;">25</span> <span style="color: #000000;">&#41;</span><br />oCmd:<span style="color: #000000;">Parameters</span>:<span style="color: #000000;">Append</span><span style="color: #000000;">&#40;</span> oParam <span style="color: #000000;">&#41;</span><br />oParam := oCmd:<span style="color: #000000;">CreateParameter</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"cPartName"</span>,adChar, adParamInput, <span style="color: #000000;">25</span> <span style="color: #000000;">&#41;</span><br />oCmd:<span style="color: #000000;">Parameters</span>:<span style="color: #000000;">Append</span><span style="color: #000000;">&#40;</span> oParam <span style="color: #000000;">&#41;</span><br />oParam := oCmd:<span style="color: #000000;">CreateParameter</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"cQty"</span>,adChar, adParamInput, <span style="color: #000000;">25</span> <span style="color: #000000;">&#41;</span><br />oCmd:<span style="color: #000000;">Parameters</span>:<span style="color: #000000;">Append</span><span style="color: #000000;">&#40;</span> oParam <span style="color: #000000;">&#41;</span><br />oParam := oCmd:<span style="color: #000000;">CreateParameter</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"cColumName"</span>,adChar, adParamInput, <span style="color: #000000;">25</span> <span style="color: #000000;">&#41;</span><br />oCmd:<span style="color: #000000;">Parameters</span>:<span style="color: #000000;">Append</span><span style="color: #000000;">&#40;</span> oParam <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #B900B9;">// Assigning Values to the Paramter</span><br /><span style="color: #00C800;">TRY</span><br />&nbsp; &nbsp;oCmd:<span style="color: #000000;">Parameters</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"cPartNo"</span> <span style="color: #000000;">&#41;</span>:<span style="color: #000000;">Value</span> := SparMast->PART<br />&nbsp; &nbsp;oCmd:<span style="color: #000000;">Parameters</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"cPartName"</span> <span style="color: #000000;">&#41;</span>:<span style="color: #000000;">Value</span> := Rtrim<span style="color: #000000;">&#40;</span>Ltrim<span style="color: #000000;">&#40;</span>SparMast->DESC<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;oCmd:<span style="color: #000000;">Parameters</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"cQty"</span> <span style="color: #000000;">&#41;</span>:<span style="color: #000000;">Value</span> := LTrim<span style="color: #000000;">&#40;</span> Str<span style="color: #000000;">&#40;</span>Int<span style="color: #000000;">&#40;</span>SparMast->CURR_QTY<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> &nbsp;<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp;oCmd:<span style="color: #000000;">Parameters</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"cColumName"</span> <span style="color: #000000;">&#41;</span>:<span style="color: #000000;">Value</span> := <span style="color: #ff0000;">"Alpy_Parvr_Qty"</span><br />CATCH oError<br />&nbsp; &nbsp;ShowSqlError<span style="color: #000000;">&#40;</span> oError <span style="color: #000000;">&#41;</span><br />END&nbsp;&nbsp; &nbsp; <br /><br /><span style="color: #B900B9;">// Executing or Calling Stored Procedure&nbsp; &nbsp; </span><br /><span style="color: #00C800;">TRY</span><br />&nbsp; &nbsp;oCmd:<span style="color: #000000;">Execute</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />CATCH oError<br />&nbsp; &nbsp;ShowSqlError<span style="color: #000000;">&#40;</span> oError <span style="color: #000000;">&#41;</span><br />END&nbsp;<br />&nbsp;</div>[/code:pirhx5yi]Regards [b:pirhx5yi]Anser[/b:pirhx5yi]
ADO STORED PROCEDURES
Buenas Tardes, alguien tendra un ejemplo de como llamar un store procedure y pasarles sus parametros MS-SQLSERVER a traves de ADO. Gracias.
ADO STORED PROCEDURES
Select Tu_procedimiento( parametros ) Saludos
ADO STORED PROCEDURES
Gracias, por responder lo hago de esa manera y me da el siguiente error: Class: 'ERROR' has no exported method [code=fw:120ud9zj]<div class="fw" id="{CB}" style="font-family: monospace;">cad_sql0:=<span style="color: #ff0000;">"SELECT pp_actualiza_stock(@co_art='"</span>+xc_art+<span style="color: #ff0000;">"',@co_alma='"</span>+xc_alma+<span style="color: #ff0000;">"',@total_art="</span>+str<span style="color: #000000;">&#40;</span>xtot_art<span style="color: #000000;">&#41;</span><br />         cad_sql0:=cad_sql0+<span style="color: #ff0000;">",@tipo_stock='stock_act',@costo_b="</span>+str<span style="color: #000000;">&#40;</span>xuct<span style="color: #000000;">&#41;</span>+<span style="color: #ff0000;">",@fecha_mov='"</span>+dtoc<span style="color: #000000;">&#40;</span>xf_lot<span style="color: #000000;">&#41;</span><br />         cad_sql0:=cad_sql0+<span style="color: #ff0000;">"',@stotal_art="</span>+str<span style="color: #000000;">&#40;</span>xst_art<span style="color: #000000;">&#41;</span>+<span style="color: #ff0000;">",@costo_om="</span>+str<span style="color: #000000;">&#40;</span>xuctom<span style="color: #000000;">&#41;</span>+<span style="color: #ff0000;">",@total_uni="</span>+str<span style="color: #000000;">&#40;</span>xtot_uni<span style="color: #000000;">&#41;</span><br />         cad_sql0:=cad_sql0+<span style="color: #ff0000;">",@co_us_in='PROFIT',@co_sucu='01',@r_stock_neg=2,@accion='R',@desde='NDD')"</span><br />                 oRs := CreateObject<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"ADODB.RecordSet"</span><span style="color: #000000;">&#41;</span>   <br />         ors:<span style="color: #000000;">CursorType</span>     = adOpenDynamic <br />                 ors:<span style="color: #000000;">CursorLocation</span> = adUseClient<br />                 ors:<span style="color: #000000;">LockType</span>       = adLockOptimistic<br />                 oRs:<span style="color: #000000;">ActiveConnection</span>:= bc:<span style="color: #000000;">ado</span><br />                 oRs:<span style="color: #000000;">source</span> := cad_Sql0<br />                 oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /> </div>[/code:120ud9zj]
ADO STORED PROCEDURES
No entiendo como pasas los parámetros, aqui un ejemplo [code=fw:ij4mydjj]<div class="fw" id="{CB}" style="font-family: monospace;"><br />&nbsp; &nbsp; &nbsp; &nbsp; cQuery &nbsp; &nbsp; := <span style="color: #ff0000;">"Select Neto( "</span> + cNroLegajo + <span style="color: #ff0000;">" ), Bruto( "</span> + cNroLegajo + <span style="color: #ff0000;">" )"</span><br />&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;oRec := TOleAuto<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> : <span style="color: #00C800;">New</span> <span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"ADODB.RecordSet"</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; oRec : <span style="color: #000000;">CursorLocation</span> &nbsp; &nbsp; := adUseClient<br />&nbsp; &nbsp; &nbsp; &nbsp; oRec : <span style="color: #000000;">CursorType</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= adOpenDynamic<br />&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; oRec : <span style="color: #000000;">LockType</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := adLockOptimistic<br />&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; oRec : <span style="color: #000000;">ActiveConnection</span> := oVarGlobales : <span style="color: #000000;">oCon</span><br />&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; oRec : <span style="color: #000000;">Source</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := cQuery<br />&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; oRec : <span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />&nbsp;</div>[/code:ij4mydjj] Saludos
ADO STORED PROCEDURES
Y cual es el nombre del procedimiento ahi en tu ejemplo y cuales son los parametros? gracias
ADO STORED PROCEDURES
Neto y bruto son los procedimientos, y cNroLegajo es el parámetro. Sería bueno que que pusieras aqui como programaste el procedimiento Saludos
ADO STORED PROCEDURES
me sigue dando el mismo error cad_sql0:="SELECT pp_actualiza_stock('"+xc_art+"','"+xc_alma+"',"+str(xtot_art) cad_sql0:=cad_sql0+",'stock_act',"+str(xuct)+",'"+dtoc(xf_lot) cad_sql0:=cad_sql0+"',"+str(xst_art)+","+str(xuctom)+","+str(xtot_uni) cad_sql0:=cad_sql0+",'PROFIT','01',2,'R','NDD')" es un procedimiento almacenado en el server MS-SQLSERVER [code=fw:2jdyjeb5]<div class="fw" id="{CB}" style="font-family: monospace;"><br />USE <span style="color: #000000;">&#91;</span>demo<span style="color: #000000;">&#93;</span><br />GO<br /><span style="color: #B900B9;">/****** Object: &nbsp;StoredProcedure [dbo].[pp_actualiza_stock] &nbsp; &nbsp;Script Date: 03/11/2013 15:08:14 ******/</span><br />SET ANSI_NULLS <span style="color: #0000ff;">ON</span><br />GO<br />SET QUOTED_IDENTIFIER <span style="color: #0000ff;">ON</span><br />GO<br /><br /><br />ALTER PROC <span style="color: #000000;">&#91;</span>dbo<span style="color: #000000;">&#93;</span>.<span style="color: #000000;">&#91;</span>pp_actualiza_stock<span style="color: #000000;">&#93;</span><br /><span style="color: #B900B9;">/******************************************************************************<br />* Stored Procedure : pp_actualiza_stock &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* Fecha Creación &nbsp; : 22/11/2001 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* Parámetros &nbsp; &nbsp; &nbsp; : - @co_art char(30) código del articulo al cual se le mo- *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;difica el stock. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @co_alma char(6) código del almacen donde se afectará &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;el stock. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @total_art decimal(28,12) cantidad de artículos. &nbsp; &nbsp; &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @tipo_stock char(9) tipo de operación a ser realizada: *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- stock_com --> comprometido, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- stock_act --> actual, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- stock_des --> por despachar, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- stock_lle --> por llegar. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @costo_b decimal(28,12) costo en la moneda base. &nbsp; &nbsp; &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @fecha_mov smalldatetime fecha del movimiento. &nbsp; &nbsp; &nbsp; &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @stotal_art decimal(28,12) cantidad de artículos en la *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;unidad secundaria. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @costo_om decimal(28,12) costa en otra moneda. &nbsp; &nbsp; &nbsp; &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @total_uni decimal(28,12) unidad de la venta. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @co_us_in char(6) usuario que realiza la operación. &nbsp; &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @co_sucu char(6) sucursal del movimiento. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @r_stock_neg tinyint indica cual será el comportamien- *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;to con respecto al stock negativo: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- 0 --> indica que no se puede facturar en negativo. &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- 1 --> indica que se debe preguntar al usuario si de- *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sea facturar con estoc en negativo. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- 2 --> indica que puede facturar con stock en negati- *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vo o que la respuesta fue positiva. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @accion char(1) indica cual es el tipo de operación a &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;realizar sobre el stock: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- S --> aumentar el stock. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- R --> disminuir el stock. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- @desde char(4) indica desde donde se llama a este &nbsp; &nbsp; &nbsp;*<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;procedimiento. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* Descripción &nbsp; &nbsp; &nbsp;: Este procedimiento se encarga modificar el stock de un &nbsp; *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;artículo y de manejar el esquema de los casos de negati- *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vo de acuerdo a los parámetros que recibe. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* Desarrollador &nbsp; &nbsp;: Noel Quiroz A. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />******************************************************************************/</span><br />@co_art char<span style="color: #000000;">&#40;</span><span style="color: #000000;">30</span><span style="color: #000000;">&#41;</span>,@co_alma char<span style="color: #000000;">&#40;</span><span style="color: #000000;">6</span><span style="color: #000000;">&#41;</span>,@total_art decimal<span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span>,@tipo_stock char<span style="color: #000000;">&#40;</span><span style="color: #000000;">9</span><span style="color: #000000;">&#41;</span>,<br />@costo_b decimal<span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span>,@fecha_mov smalldatetime,@stotal_art decimal<span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span>,<br />@nro_lote char<span style="color: #000000;">&#40;</span><span style="color: #000000;">10</span><span style="color: #000000;">&#41;</span>,@fech_lote smalldatetime,@costo_om decimal<span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span>,<br />@total_uni decimal<span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span>,@co_us_in char<span style="color: #000000;">&#40;</span><span style="color: #000000;">6</span><span style="color: #000000;">&#41;</span>,@co_sucu char<span style="color: #000000;">&#40;</span><span style="color: #000000;">6</span><span style="color: #000000;">&#41;</span>,@r_stock_neg tinyint,<br />@p_lotefec_amb bit,@p_lotefec_res bit,@accion char<span style="color: #000000;">&#40;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span>,@desde char<span style="color: #000000;">&#40;</span><span style="color: #000000;">4</span><span style="color: #000000;">&#41;</span><br />as<br />declare @cantidad_act decimal <span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span>,@scantidad_act decimal <span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; @total_artc decimal<span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span> &nbsp; ,@status_sal int,@des_art varchar<span style="color: #000000;">&#40;</span><span style="color: #000000;">120</span><span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; @ult_cos_un decimal<span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span> &nbsp; ,@cos_pro_un decimal<span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; @ult_cos_om decimal<span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span> &nbsp; ,@cos_pro_om decimal<span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; @fec_ult_co smalldatetime &nbsp; &nbsp;,@fec_pro_un smalldatetime,<br />&nbsp; &nbsp; &nbsp; &nbsp; @fec_ult_om smalldatetime &nbsp; &nbsp;,@fec_pro_om smalldatetime,<br />&nbsp; &nbsp; &nbsp; &nbsp; @relac_aut int &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,@uni_relac decimal<span style="color: #000000;">&#40;</span><span style="color: #000000;">28</span>,<span style="color: #000000;">12</span><span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; @p_lotenro bit &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,@p_lotefec bit,<br />&nbsp; &nbsp; &nbsp; &nbsp; @lote bit &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /><br /><span style="color: #0000ff;">select</span> @des_art &nbsp; &nbsp;= art_des &nbsp; ,@cantidad_act = stock_act,<br />&nbsp; &nbsp; &nbsp; &nbsp;@ult_cos_un = ult_cos_un,@cos_pro_un = cos_pro_un,<br />&nbsp; &nbsp; &nbsp; &nbsp;@ult_cos_om = ult_cos_om,@cos_pro_om = cos_pro_om,<br />&nbsp; &nbsp; &nbsp; &nbsp;@fec_ult_co = fec_ult_co,@fec_pro_un = fec_cos_pr,<br />&nbsp; &nbsp; &nbsp; &nbsp;@fec_ult_om = fec_ult_om,@fec_pro_om = fec_pro_om,<br />&nbsp; &nbsp; &nbsp; &nbsp;@relac_aut &nbsp;= relac_aut ,@uni_relac &nbsp;= uni_relac,<br />&nbsp; &nbsp; &nbsp; &nbsp;@lote &nbsp; &nbsp; &nbsp; = lote<br /><span style="color: #0000ff;">from</span> art <span style="color: #0000ff;">where</span> co_art = @co_Art<br /><br /><span style="color: #00C800;">if</span> @relac_aut in <span style="color: #000000;">&#40;</span><span style="color: #000000;">2</span>,<span style="color: #000000;">3</span><span style="color: #000000;">&#41;</span> and @uni_relac != <span style="color: #000000;">0</span><br />&nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; set @stotal_art = <span style="color: #000000;">0</span><br />&nbsp; &nbsp;end<br /><br /><span style="color: #0000ff;">select</span> @p_lotenro = p_lotenro, @p_lotefec = p_lotefec <span style="color: #0000ff;">from</span> par_emp<br /><br /><span style="color: #B900B9;">/******************************************************************************<br />* Proceso para el Stock comprometido. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />******************************************************************************/</span><br /><span style="color: #00C800;">if</span> @tipo_stock = <span style="color: #ff0000;">'stock_com'</span> <br />&nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @accion = <span style="color: #ff0000;">'S'</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> art set stock_com = stock_com + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_com = sstock_com + @stotal_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo aumentar el stock comprometido en la tabla de artículos '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> not <span style="color: #0000ff;">exists</span> <span style="color: #000000;">&#40;</span><span style="color: #0000ff;">select</span> * <span style="color: #0000ff;">from</span> st_almac <span style="color: #0000ff;">where</span> co_alma = @co_alma<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and co_art = @co_art<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert into st_almac <span style="color: #000000;">&#40;</span>co_alma,co_art<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; values <span style="color: #000000;">&#40;</span>@co_alma,@co_art<span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo insertar registro en la tabla de st_almac para el stock comprometido '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art + <span style="color: #ff0000;">' en el almacén '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> st_almac set stock_com = stock_com + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_com = sstock_com + @stotal_art <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and co_alma = @co_alma<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo aumentar el stock comprometido en la tabla de artículos '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art + <span style="color: #ff0000;">' en el almacén '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">else</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> st_almac set stock_com = stock_com - <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_com = sstock_com - @stotal_art <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and co_alma = @co_alma<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo disminuir el stock comprometido en la tabla de artículos '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art + <span style="color: #ff0000;">' en el almacén '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> art set stock_com = stock_com - <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sstock_com = sstock_com - @stotal_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo disminuir el stock comprometido en la tabla de artículos '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp;end<br /><br /><span style="color: #B900B9;">/******************************************************************************<br />* Proceso para el Stock actual. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />******************************************************************************/</span><br /><span style="color: #00C800;">if</span> @tipo_stock = <span style="color: #ff0000;">'stock_act'</span> <br />&nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @accion = <span style="color: #ff0000;">'S'</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #B900B9;">/*Actualizar los costos*/</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @fecha_mov >= @fec_ult_co<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set @fec_ult_co = @fecha_mov<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set @ult_cos_un = @costo_b<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set @cos_pro_un = <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>@ult_cos_un * @cantidad_act<span style="color: #000000;">&#41;</span> + <span style="color: #000000;">&#40;</span>@total_art * @costo_b<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; / <span style="color: #000000;">&#40;</span>@cantidad_act + @total_art<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> art set stock_act = stock_act + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_act = sstock_act + @stotal_art,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ult_cos_un = @ult_cos_un,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cos_pro_un = @cos_pro_un,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fec_ult_co = @fec_ult_co<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo aumentar el stock actual en la tabla de artículos '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> &nbsp;+ <span style="color: #ff0000;">' '</span> + @des_art as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> not <span style="color: #0000ff;">exists</span> <span style="color: #000000;">&#40;</span><span style="color: #0000ff;">select</span> * <span style="color: #0000ff;">from</span> st_almac <span style="color: #0000ff;">where</span> co_alma = @co_alma<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and co_art = @co_art<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert into st_almac <span style="color: #000000;">&#40;</span>co_alma,co_art<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; values <span style="color: #000000;">&#40;</span>@co_alma,@co_art<span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo insertar registro en la tabla de st_almac para el stock actual '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art + <span style="color: #ff0000;">' en el almacén '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> st_almac set stock_act = stock_act + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_act = sstock_act + @stotal_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and co_alma = @co_alma<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo aumentar el stock actual en la tabla de artículos '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art + <span style="color: #ff0000;">' en el almacén '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">else</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br /><span style="color: #B900B9;">/******************************************************************************<br />* Manejo de lotes, para este fin se utilizan 3 variables: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* - p_lotenro --> esta indica si en parámetros de la empresa está activada la *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; marca de trabajar los lotes por número. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />* - p_lotefec --> esta indica si en parámetros de la empresa está activada la *<br />* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; marca de trabajar los lotes por fecha de vencimiento. &nbsp; &nbsp; &nbsp; *<br />* - lote &nbsp; &nbsp; &nbsp;--> esta indica si el artículo en curso maneja lotes. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * <br />******************************************************************************/</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> <span style="color: #000000;">&#40;</span>@p_lotenro = <span style="color: #000000;">1</span> or @p_lotefec = <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> and @lote = <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> len<span style="color: #000000;">&#40;</span>rtrim<span style="color: #000000;">&#40;</span>@nro_lote<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> = space<span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">select</span> <span style="color: #000000;">3</span> as Errores,<span style="color: #ff0000;">'El número de lote para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">' no fue especificado '</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">return</span> <span style="color: #000000;">3</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @fecha_mov > @fech_lote and @p_lotefec_res = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @p_lotefec_amb = <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">3</span> as Errores,<span style="color: #ff0000;">'El número de lote '</span> + rtrim<span style="color: #000000;">&#40;</span>@nro_lote<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' se encuentra vencido '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; convert<span style="color: #000000;">&#40;</span>varchar,@fech_lote,<span style="color: #000000;">103</span><span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">return</span> <span style="color: #000000;">3</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">else</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">if</span> @p_lotefec_amb = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">select</span> <span style="color: #000000;">2</span> as Errores,<span style="color: #ff0000;">'El número de lote '</span> + rtrim<span style="color: #000000;">&#40;</span>@nro_lote<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' se encuentra vencido '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;convert<span style="color: #000000;">&#40;</span>varchar,@fech_lote,<span style="color: #000000;">103</span><span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'.'</span> + char<span style="color: #000000;">&#40;</span><span style="color: #000000;">13</span><span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'Desea Continuar?'</span> as Mensaje<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">return</span> <span style="color: #000000;">2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> st_lote set stock_act &nbsp; &nbsp; &nbsp;= stock_act - <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@cantidad_act &nbsp;= stock_act - <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_act &nbsp; &nbsp; = sstock_act - @stotal_art,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@scantidad_act = sstock_act - @stotal_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art &nbsp; = @co_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and co_alma &nbsp;= @co_alma<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and nro_lote = @nro_lote<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo actualizar el stock actual para el lote '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@nro_lote as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @cantidad_act < <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @r_stock_neg = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @desde in <span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'FACT'</span>,<span style="color: #ff0000;">'COMP'</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">3</span> as Errores,<span style="color: #ff0000;">'No hay suficiente stock para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' almacén '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' Nro lote '</span> + rtrim<span style="color: #000000;">&#40;</span>@nro_lote<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'.'</span> + char<span style="color: #000000;">&#40;</span><span style="color: #000000;">13</span><span style="color: #000000;">&#41;</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'Stock actual: '</span> + convert<span style="color: #000000;">&#40;</span>varchar,<span style="color: #000000;">&#40;</span>@cantidad_act + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">return</span> <span style="color: #000000;">3</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">else</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">if</span> @r_stock_neg = <span style="color: #000000;">2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">select</span> <span style="color: #000000;">2</span> as Errores,<span style="color: #ff0000;">'No hay suficiente stock para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' almacén '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' Nro lote '</span> + rtrim<span style="color: #000000;">&#40;</span>@nro_lote<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'.'</span> + char<span style="color: #000000;">&#40;</span><span style="color: #000000;">13</span><span style="color: #000000;">&#41;</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'Stock actual: '</span> + convert<span style="color: #000000;">&#40;</span>varchar,<span style="color: #000000;">&#40;</span>@cantidad_act + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> &nbsp;+ char<span style="color: #000000;">&#40;</span><span style="color: #000000;">13</span><span style="color: #000000;">&#41;</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'Desea Continuar?'</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">return</span> <span style="color: #000000;">2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> <span style="color: #0000ff;">exists</span> <span style="color: #000000;">&#40;</span><span style="color: #0000ff;">select</span> * <span style="color: #0000ff;">from</span> art <span style="color: #0000ff;">where</span> co_art = @co_art <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and compuesto = <span style="color: #000000;">1</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and @desde in <span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'FACT'</span>,<span style="color: #ff0000;">'COMP'</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and stock_act < @total_art<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> @total_artc = <span style="color: #000000;">&#40;</span>@total_art - stock_act<span style="color: #000000;">&#41;</span> <span style="color: #0000ff;">from</span> art <span style="color: #0000ff;">where</span> co_art = @co_art<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exec @status_sal = pp_genera_compuesto @co_art,@co_alma,@total_artc,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@tipo_stock,@costo_b,@fecha_mov, <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@stotal_art,@costo_om,@total_uni,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@co_us_in,@co_sucu,@r_stock_neg,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@accion<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @status_sal != <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">return</span> <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp;<span style="color: #00C800;">if</span> not <span style="color: #0000ff;">exists</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">select</span> * <span style="color: #0000ff;">from</span> st_almac <span style="color: #0000ff;">where</span> co_art &nbsp;= @co_art and co_alma = @co_alma<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Insert into st_almac <span style="color: #000000;">&#40;</span>co_art, co_alma<span style="color: #000000;">&#41;</span> values <span style="color: #000000;">&#40;</span>@co_art, @co_alma<span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> st_almac set stock_act &nbsp; &nbsp; &nbsp;= stock_act - <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @cantidad_act &nbsp;= stock_act - <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sstock_act &nbsp; &nbsp; = sstock_act - @stotal_art,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @scantidad_act = sstock_act - @stotal_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art &nbsp;= @co_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and co_alma = @co_alma<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo actualizar el stock actual para el almacen '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@co_alma as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @cantidad_act < <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @r_stock_neg = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @desde in <span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'FACT'</span>,<span style="color: #ff0000;">'COMP'</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">3</span> as Errores,<span style="color: #ff0000;">'No hay suficiente stock, en el almacén: '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">' para el artículo: '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + &nbsp;<span style="color: #ff0000;">' '</span> + rtrim<span style="color: #000000;">&#40;</span>@des_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'.'</span> + char<span style="color: #000000;">&#40;</span><span style="color: #000000;">13</span><span style="color: #000000;">&#41;</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ <span style="color: #ff0000;">'Stock actual: '</span> + convert<span style="color: #000000;">&#40;</span>varchar,<span style="color: #000000;">&#40;</span>@cantidad_act + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">return</span> <span style="color: #000000;">3</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">else</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">if</span> @r_stock_neg = <span style="color: #000000;">2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">select</span> <span style="color: #000000;">2</span> as Errores,<span style="color: #ff0000;">'No hay suficiente stock, en el almacén: '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">' para el artículo: '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + rtrim<span style="color: #000000;">&#40;</span>@des_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'.'</span> + <span style="color: #ff0000;">' Stock actual: '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;convert<span style="color: #000000;">&#40;</span>varchar,<span style="color: #000000;">&#40;</span>@cantidad_act + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'.'</span> + char<span style="color: #000000;">&#40;</span><span style="color: #000000;">13</span><span style="color: #000000;">&#41;</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'Desea Continuar?'</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">return</span> <span style="color: #000000;">2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @scantidad_act < <span style="color: #000000;">0</span> and @stotal_art != <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @r_stock_neg = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @desde in <span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'FACT'</span>,<span style="color: #ff0000;">'COMP'</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">3</span> as Errores,<span style="color: #ff0000;">'No hay suficiente stock(Secun), en el almacén: '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">' para el artículo: '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + &nbsp;<span style="color: #ff0000;">' '</span> + rtrim<span style="color: #000000;">&#40;</span>@des_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'.'</span> + char<span style="color: #000000;">&#40;</span><span style="color: #000000;">13</span><span style="color: #000000;">&#41;</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ <span style="color: #ff0000;">'Stock actual: '</span> + convert<span style="color: #000000;">&#40;</span>varchar,<span style="color: #000000;">&#40;</span>@scantidad_act + <span style="color: #000000;">&#40;</span>@stotal_art * @total_uni<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">return</span> <span style="color: #000000;">3</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">else</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">if</span> @r_stock_neg = <span style="color: #000000;">2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">select</span> <span style="color: #000000;">2</span> as Errores,<span style="color: #ff0000;">'No hay suficiente stock(Secun), en el almacén: '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">' para el artículo: '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + rtrim<span style="color: #000000;">&#40;</span>@des_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'.'</span> + <span style="color: #ff0000;">' Stock actual: '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;convert<span style="color: #000000;">&#40;</span>varchar,<span style="color: #000000;">&#40;</span>@scantidad_act + <span style="color: #000000;">&#40;</span>@stotal_art * @total_uni<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">'.'</span> + char<span style="color: #000000;">&#40;</span><span style="color: #000000;">13</span><span style="color: #000000;">&#41;</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'Desea Continuar?'</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">return</span> <span style="color: #000000;">2</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> art set stock_act &nbsp;= stock_act - <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_act = sstock_act - @stotal_art <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo disminuir el stock actual en la tabla de artículos '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art as Mensaje<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp;end<br /><br /><span style="color: #B900B9;">/******************************************************************************<br />* Proceso para el Stock por despachar. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />******************************************************************************/</span><br /><span style="color: #00C800;">if</span> @tipo_stock = <span style="color: #ff0000;">'stock_des'</span> <br />&nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @accion = <span style="color: #ff0000;">'S'</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> art set stock_des = stock_des + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_des = sstock_des + @stotal_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo aumentar el stock por despachar en la tabla de artículos '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> not <span style="color: #0000ff;">exists</span> <span style="color: #000000;">&#40;</span><span style="color: #0000ff;">select</span> * <span style="color: #0000ff;">from</span> st_almac <span style="color: #0000ff;">where</span> co_alma = @co_alma<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and co_art = @co_art<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert into st_almac <span style="color: #000000;">&#40;</span>co_alma,co_art<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; values <span style="color: #000000;">&#40;</span>@co_alma,@co_art<span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo insertar registro en la tabla de st_almac para el stock por despachar '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art + <span style="color: #ff0000;">' en el almacén '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> st_almac set stock_des = stock_des + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_des = sstock_des + @stotal_art <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and co_alma = @co_alma<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo aumentar el stock por despachar en la tabla de artículos '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art + <span style="color: #ff0000;">' en el almacén '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">else</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> st_almac set stock_des = stock_des - <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_des = sstock_des - @stotal_art <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and co_alma = @co_alma<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo disminuir el stock por despachar en la tabla de artículos '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art + <span style="color: #ff0000;">' en el almacén '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> art set stock_des = stock_des - <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sstock_des = sstock_des - @stotal_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo disminuir el stock por despachar en la tabla de artículos '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp;end<br /><br /><span style="color: #B900B9;">/******************************************************************************<br />* Proceso para el Stock por entregar. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />******************************************************************************/</span><br /><span style="color: #00C800;">if</span> @tipo_stock = <span style="color: #ff0000;">'stock_lle'</span> <br />&nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @accion = <span style="color: #ff0000;">'S'</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> art set stock_lle = stock_lle + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_lle = sstock_lle + @stotal_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo aumentar el stock por llegar en la tabla de artículos '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> not <span style="color: #0000ff;">exists</span> <span style="color: #000000;">&#40;</span><span style="color: #0000ff;">select</span> * <span style="color: #0000ff;">from</span> st_almac <span style="color: #0000ff;">where</span> co_alma = @co_alma<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and co_art = @co_art<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert into st_almac <span style="color: #000000;">&#40;</span>co_alma,co_art<span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; values <span style="color: #000000;">&#40;</span>@co_alma,@co_art<span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo insertar registro en la tabla de st_almac para el stock poe llegar '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art + <span style="color: #ff0000;">' en el almacén '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> st_almac set stock_lle = stock_lle + <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_lle = sstock_lle + @stotal_art <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and co_alma = @co_alma<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo aumentar el stock por llegar en la tabla de artículos '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art + <span style="color: #ff0000;">' en el almacén '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">else</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> st_almac set stock_lle = stock_lle - <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sstock_lle = sstock_lle - @stotal_art <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and co_alma = @co_alma<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo aumentar el stock por llegar en la tabla de artículos '</span> +<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> + <span style="color: #ff0000;">' '</span> + @des_art + <span style="color: #ff0000;">' en el almacén '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rtrim<span style="color: #000000;">&#40;</span>@co_alma<span style="color: #000000;">&#41;</span> as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">update</span> art set stock_lle = stock_lle - <span style="color: #000000;">&#40;</span>@total_art * @total_uni<span style="color: #000000;">&#41;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sstock_lle = sstock_lle - @stotal_art<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">where</span> co_art = @co_art<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">if</span> @@error != <span style="color: #000000;">0</span> or @@rowcount = <span style="color: #000000;">0</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #000000;">1</span> as Errores,<span style="color: #ff0000;">'No se pudo disminuir el stock por llegar en la tabla de artículos '</span> + <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'para el artículo '</span> + rtrim<span style="color: #000000;">&#40;</span>@co_art<span style="color: #000000;">&#41;</span> &nbsp;+ <span style="color: #ff0000;">' '</span> + @des_art as Mensaje<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00C800;">RETURN</span> <span style="color: #000000;">1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br />&nbsp; &nbsp;end<br /><br /><span style="color: #00C800;">RETURN</span><br />&nbsp;</div>[/code:2jdyjeb5]
ADO STORED PROCEDURES
No trabajo mssql, imagino que el paso de parámetros debe estar normalizado para cualquier motor sql. Lo que no entiendo son las igualdades que ponés en el paso de parámetros po ej '@co_art='"+xc_art', en MySql el paso sería solamente el valor. Acá se me acabó la sapiencia. Saludos
ADO STORED PROCEDURES
Em sql server (microsoft) los store procedures se llaman con EXECUTE no con SELECT. por ejemplo, si necesito el SP me devuelva un recordset: [code=fw:1tc97y1v]<div class="fw" id="{CB}" style="font-family: monospace;"><br /><br />oClientes := adoRecordSet<span style="color: #000000;">&#40;</span> oApp:<span style="color: #000000;">oAdoConnector</span>, <span style="color: #ff0000;">"EXEC sp_buscar_cliente '"</span> + aVars<span style="color: #000000;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">&#93;</span> + <span style="color: #ff0000;">"'"</span> <span style="color: #000000;">&#41;</span><br /><span style="color: #0000ff;">xBrowse</span><span style="color: #000000;">&#40;</span> oClientes <span style="color: #000000;">&#41;</span><br /><br /><span style="color: #00C800;">Function</span> ADORecordSet<span style="color: #000000;">&#40;</span> oConnect, cSql, lConnect <span style="color: #000000;">&#41;</span><br /><br />&nbsp; &nbsp;<span style="color: #00C800;">Local</span> oRs<br />&nbsp; &nbsp;<span style="color: #00C800;">Local</span> cError := <span style="color: #ff0000;">"No se ha podido crear el objeto contenedor RECORDSET !"</span><br /><br />&nbsp; &nbsp;<span style="color: #00C800;">try</span><br />&nbsp; &nbsp; &nbsp; oRs := CreateObject<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"ADODB.RecordSet"</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; oRs:<span style="color: #000000;">CursorLocation</span> &nbsp;:= <span style="color: #000000;">3</span><br />&nbsp; &nbsp; &nbsp; oRs:<span style="color: #000000;">LockType</span> &nbsp; &nbsp; &nbsp; &nbsp;:= <span style="color: #000000;">4</span><br />&nbsp; &nbsp; &nbsp; oRs:<span style="color: #000000;">ActiveConnection</span>:= oConnect<br />&nbsp; &nbsp; &nbsp; oRs:<span style="color: #000000;">source</span> := cSql<br />&nbsp; &nbsp; &nbsp; oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; lConnect := .t.<br />&nbsp; &nbsp;catch<br />&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; msadoerror<span style="color: #000000;">&#40;</span> cSql, <span style="color: #ff0000;">"Error de Conexion con servidor"</span> <span style="color: #000000;">&#41;</span><br />&nbsp; &nbsp; &nbsp; <span style="color: #00C800;">return</span> <span style="color: #00C800;">nil</span><br /><br />&nbsp; &nbsp;end <span style="color: #00C800;">try</span><br /><br /><span style="color: #00C800;">Return</span> oRS<br /><br /><br />&nbsp;</div>[/code:1tc97y1v]
ADO Sort error
I using ors:sort := "field1,field2" but I get a error. DB Mysql CursorLocation = adUseClient. Does anyone knows what might be the cause and how to solve it?
ADO Sort error
Antonio I always put my sort values as parameters within parenthesis .. Try it this way: [code=fw:36lx90vt]<div class="fw" id="{CB}" style="font-family: monospace;"><br />oRs:<span style="color: #000000;">sort</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"[field1],[field2]"</span> <span style="color: #000000;">&#41;</span> <br /> </div>[/code:36lx90vt] Rick Lipkin
ADO Sort error
oRs:Sort := "field1,field2" is perfectly valid. But oRs:Sort works only on client side recordsets
ADO Sort error
Thanks!
ADO Sql Query limitations ??
To AllI have put together a simple sql query that joins two tables that I have cut and pasted out of MS SQL Studio.I know the query works .. every time I try to execute this query, my computer locks up .. any ideas here ??Rick Lipkin//----------cSQL := "SELECT proj.PROJECTEID, proj.PROJNAME, proj.DESCRIP, proj.START_DATE, proj.END_DATE, "+; "proj.EST_BUDGET, proj.FUNDED, proj.USEREID, proj.PROJMGR, "+; "proj.REPORTING, proj.FREQUENCYEID, proj.FREQUENCY, proj.ROW_COLOR, proj.EMAIL, "+; "proj.ACTIVE, proj.CONTRACT, proj.ENTRYBY, proj.ENTRYDATE, "+; "proj.CREATEDBY, proj.CREATEDATE, proj.UPDATED, spon.PROJECTEID AS Expr1, spon.SPONSORID "+; "FROM PROJECT AS proj INNER JOIN P_SPONSOR AS spon ON proj.PROJECTEID = spon.PROJECTEID "+; "WHERE (proj.PROJMGR = 'LIPKINRM') OR (spon.SPONSORID = 'LIPKINRM')"oRsProj := TOleAuto():New( "ADODB.Recordset" )oRsProj:CursorType := 1 // opendkeysetoRsProj:CursorLocation := 3 // local cacheoRsProj:LockType := 3 // lockoportunisticTRY oRsProj:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )CATCH oErr MsgInfo( "Error in Opening PROJECT table" ) oDlg:End() RETURN(.F.)END TRY
ADO Sql Query limitations ??
To AllI have this problem FIXED .. as it turned out .. it had nothing directly to do with the query, but I was displaying cSQL on a title bar for a wait dialog box .. see code :It was the length of the variable cSQL that was being passed on the title line that 'hosed' everything up .. Until I placed a few msgbox's before and after did I realize that the Openup() function was not even being executed .. The program stopped at the wrapper dialog ..I just could not believe it ..Thanks, the query ran as expected and returned all the rows it was supposed to !!!Rick Lipkin//-------cLEVEL2 := "Y"DO CASECASE xSUPER = 'Y' cSQL := "SELECT * from PROJECT order by Projname"CASE xPROJ = 'Y' .and. xSUPER <> 'Y' IF cLEVEL2 = "N" cSQL := "SELECT * from PROJECT order by Projname" ELSE cSQL := "SELECT proj.PROJECTEID, proj.PROJNAME, proj.DESCRIP, proj.START_DATE, proj.END_DATE, "+; "proj.EST_BUDGET, proj.FUNDED, proj.USEREID, proj.PROJMGR, "+; "proj.REPORTING, proj.FREQUENCYEID, proj.FREQUENCY, proj.ROW_COLOR, proj.EMAIL, "+; "proj.ACTIVE, proj.CONTRACT, proj.ENTRYBY, proj.ENTRYDATE, "+; "proj.CREATEDBY, proj.CREATEDATE, proj.UPDATED, spon.PROJECTEID AS Expr1, spon.SPONSORID "+; "FROM PROJECT AS proj INNER JOIN P_SPONSOR AS spon ON proj.PROJECTEID = spon.PROJECTEID "+; "WHERE (proj.PROJMGR = 'LIPKINRM') OR (spon.SPONSORID = 'LIPKINRM')" ENDIF//------------------SysReFresh()lOK := .F.DEFINE DIALOG oDlg ; FROM 5, 8 to 10, 75 ; TITLE "Please be patient " ; //+cSQL ; <--- here COLOR "N/W" ; STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME ) cSAY := "Opening Initial PROJECT Data Recordset" @ 1,13 SAY oSay var cSAY of oDLG COLOR "N/W" oDLG:bStart := { | | lOK1 := _OpenUm(oDlg, cSQL, oWNDMDI, lFROMLINK, xPROJECTEID ) }ACTIVATE DIALOG oDLG CENTEREDIF lOK1 = .F. SysReFresh() RETURN(NIL)ENDIFSysReFresh()_PBrow(oWndMdi, cSQL, lFROMLINK, xPROJECTEID, cLEVEL2 )SysReFresh()Return(nil)//----------------Static Func _OpenUm(oDlg, cSQL, oWNDMDI, lFROMLINK, xPROJECTEID )LOCAL oErr, SAYING, cSTRING, cFINDIF cSQL = " " cSQL := "SELECT * FROM PROJECT order by projname"ENDIFSysReFresh()oRsProj := TOleAuto():New( "ADODB.Recordset" )oRsProj:CursorType := 1 // opendkeysetoRsProj:CursorLocation := 3 // local cacheoRsProj:LockType := 3 // lockoportunisticTRY oRsProj:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )CATCH oErr MsgInfo( "Error in Opening PROJECT table" ) oDlg:End() RETURN(.F.)END TRYSysReFresh()oDLG:END()
ADO Sql and Requery
With DBF files, i use a listbox in a dialog and display the records of the DBF . If the user want to search , he press the search button and write what he is looking for How to do the same with record set, how to requery ?? Thanks for your help . ======================= Xbase sample: select 0 use adresses set index to NAME go top DEFINE DIALOG ... REDEFINE LISBOX oLbx FIELDS ... REDEFINE BUTTON .... ACTION (RESEARCH(),oLbx:upstable(),oLbx:refresh() ACTIVATE DIALOG ... function RESEARCH() local av av:=space(20) if MsgGet (" Recherche Patient ","Search :",@av) seek trim(av) endif return .T.
ADO Sql and Requery
I use the sort option when I have multiple search possibliities .. consider this code : oRs:Sort := "fname" oRs:MoveFirst() oRs:Find("fname = '"+cFIND+"'" ) oLBX:ReFresh() SysReFresh() .. or oRs:Sort := "lname" oRs:MoveFirst() oRs:Find("lname = '"+cFIND+"'" ) oLBX:ReFresh() SysReFresh() .. Rick Lipkin
ADO Sql and Requery
Rick, Thanks for this answer but what have i to to if the date is not in the record set . I i have a table with 1 000 000 of records or more, i will not have : select * form table i will place a first scope : select * form table where NAME like "J*" and if the user want to llok for a name starting with R ... How to refresh ?
ADO anchura campos numéricos
Buenas tardes, estoy comenzando a convertir mis bases de datos DBF a MYSQL. Una vez importadas las tablas en MYSQL me he encontrado con el problema de la anchura de los campos numéricos. Primero probé con la propiedad nPrecision de los objetos Fields, pero para los tipos Int, TinyInt y BigInt siempre devuelven un valor fijo. Yo necesito el valor entre paréntesis que aparece en la creación de la tabla, por ejemplo Int(5) es un ancho de 5, en cambio nPrecision es 10 y FWADOFieldLen() es 11. Lo he conseguido solucionar usando el siguiente código : [code=fw:29ujis6j]<div class="fw" id="{CB}" style="font-family: monospace;">oRS := oCon:<span style="color: #000000;">Execute</span> <span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"SHOW CREATE TABLE "</span> + cTabla <span style="color: #000000;">&#41;</span><br />cCreateTabla := oRs:<span style="color: #000000;">Fields</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span>:<span style="color: #000000;">value</span></div>[/code:29ujis6j] De esta forma en la variable cCreateTabla se guarda una cadena de caracteres con la sentencia SQL que creó la tabla, como ejemplo : [quote:29ujis6j]CREATE TABLE `reembols` ( `ID` INT(11) NOT NULL AUTO_INCREMENT, `SERIE1` VARCHAR(2) NULL DEFAULT NULL COLLATE 'utf8_spanish_ci', `TALON` BIGINT(20) NULL DEFAULT NULL, `SERIE2` VARCHAR(3) NULL DEFAULT NULL COLLATE 'utf8_spanish_ci', `NUMERO` BIGINT(20) NULL DEFAULT NULL, `CLIENTE` VARCHAR(25) NULL DEFAULT NULL COLLATE 'utf8_spanish_ci', `FECHA` DATE NULL DEFAULT NULL, `IMPORTE` DECIMAL(11,2) NULL DEFAULT NULL, `BANCO1` VARCHAR(8) NULL DEFAULT NULL COLLATE 'utf8_spanish_ci', `BANCO` TINYINT(2) NULL DEFAULT NULL, `APUNTE` INT(5) NULL DEFAULT NULL, `IBAN` VARCHAR(34) NULL DEFAULT NULL COLLATE 'utf8_spanish_ci', PRIMARY KEY (`ID`) ) [/quote:29ujis6j] Ya sólo queda buscar el nombre del campo que queramos y sacar el número entre paréntesis. Expongo esta solución por si le sirve a algún compañero del grupo y por si alguien conoce una forma más sencilla de obtenerlo. Un saludo.
ADO anchura campos numéricos
gmart: Podrías crear los campos numérico como DECIMAL (5,2), de esa forma siempre sabrás tamaño y cantidad de decimales. Para tomar en cuenta, MySql siempre guarda el contenido como tipo carácter y el punto decimal se almacena, por tanto si defines el tamaño como (5,2) el valor máximo no será 999.99 sino 99.99. mis 2 centavos. Saludos
ADO anchura campos numéricos
Muchas gracias Armando, en mi caso estoy usando la función FW_ADOImportFromDBF para importar los DBF en MYSQL y me he encontrado que las tablas creadas automáticamente tienen campos BigInt, TinyInt, Int y Decimal. Además no ha respetado el ancho que tenían originalmente en las DBF, intentaré investigar esa función para adaptarla a lo que quiero. Por lo que me dices si necesito un campo Int(5), al pasarlo a Decimal sería (8,2). Lo tendré en cuenta, aunque con la solución que he encontrado me sirve. No sé si "SHOW CREATE TABLE" sólo la tiene MySQL, pero es el motor de base de datos que voy a usar y por ahora sigo en la adaptación a MySQL con ADO. Un saludo.
ADO anchura campos numéricos
With DBF, { "fieldname", "N", 6, 2 } uses 8 bytes including "-" sign and decimal. So it can store from -99.99 to 999.99. In MySql (and many other RDBS), DECIMAL( 5, 2 ) can store -999.99 to 999.99 Integers: MySQL INT takes only 4 bytes of storage space on the disk, but can contain values from -2147483648 to 2147483647. This is equivalent to Numeric 11,0 in DBF. If we want to store a number in this range, do we like to waste 11 bytes of space in MySql or just use 4 bytes only. In addition INT is a lot faster than Decimal.
ADO anchura campos numéricos
Muchas gracias Rao, lo tendré en cuenta para el diseño de mis tablas cuando esté funcionando al 100 por 100 con ADO y MySQL. Un saludo.
ADO and Lock
Hello, I have an invoice file with a field InvoiceNumber, when the user add a record, the invoice number must be the last one + 1 In a SQL network environment, how can i be shure that dont have 2 times the same number . With DBF, when i want to do the same, i open an other file (LOCK.DBF) in EXCLUSIVE MODE and. if neterr() return .T. , i select the INVOICE file, go bottom , place last invoicenumber in memory, i add a new record in INVOICE file , replace InvoiceNumber with last one+1 and than i close the LOCK file . If an other user try to add a record at same time, the EXCLUSIVE MODE (LOCK.DBF) return FALSE and the user is invited to try again . How to do this with SQL code ? Thanks I
ADO and Lock
The easiest and the most reliable way is to create the invoiceno field as an autoincrement field. Note: Even for DBFs (using DBFCDX) this is the current practice to use autoincrement field. FW functions for ADO make it very easy to implement
ADO and Lock
I agree with you BUTthe custumer ask me to reset the counter to 1 each month. There is a prefix in front of the invoice number who is YYYYMM-invoice number ==> 201506-0001 ..... Thanks for your help .
ADO and Lock
Understand. I'll be back with a proposal in a while
ADO and Lock
Hi, You can define a field as unique and there is no chance to have 2 same values Best regards,
ADO and Lock
Jack To my knowledge there is not a ( good ) way to lock a Sql table ... and the Ole provider usually handles all the 'opportunistic' locks for you. With that said .. I have come up with a table called [InvoiceNumbers] and when a person wishes to create a new Invoice, I open the [InvoiceNumber] table, go to the bottom in Ascending order and add a new record +1 and immediately assign the new transaction the next Invoice Number oRs:Update() .. and out, ready for the next transaction, which works quite will in a multi-user application. If the User wishes to cancel the transaction before I commit the detail .. so be it. There is just a sequence gap in the committed Invoice transactions. Rao does have a GOOD point about using an AutoNumber on the InvoiceNumber field letting the database issue the next number, however using AutoNumber especially on a primary key can EASILY lead to 'Sql Injection' from a malicious attacker that may ( covertly ) gain access to your system, as 'unlikely' as that may be .. Database Security is a BIG issue today and creating your Own Invoices Numbers under program control ( not database control ) is a good ( security ) selling point. Rick Lipkin
ADO and Lock
Jack, I put a unique index on the invoice-number. Each time a customer add a new invoice I check for the last invoice number (Query with a desc order on invoice-number and a limit of 1). Then I add directly an empty record with that invoice number to the table. So, if someone else whant to add an invoice, he will get a higher number. In an other table I record that someone is using that invoice, so nobody else can modify than invoice. Only when it is finished...
ADO and Lock
Marc, Is it possible to give a sample of code . I read in the past that it is possible to use a SQL table in exclusive mode , how to ? Thanks.
ADO and Lock
An Auto-increment field is a double edge sword that I would avoid as invoice numbers. One of the potential problems that can arise with auto-increment fields is that if the table is later merged o copied to another table, append from another table, or transported somewhere else, or even if restructured -these numbers will change. i.e... you don't have any control over auto-increment fields. Restarting sequences every month will generate duplicated invoice numbers. I think you'd want to keep monthly sequences a part from invoice numbers which must be unique. In this case I would declare the field as "unique" -that will ensure that even if badly coded, the invoice number will not be duplicated. It wouldn't be too hard to obtain the last invoice number used with a sql sentence using max. Then inside a transaction I would -try-and-retry to create the record with max(invoice#) + 1. The trying-and-re-trying inside a transaction will help solve the problem of other users racing to create an invoice # with the same number. I hope that helps. Reinaldo.
ADO and Lock
I am back with this problem . Could someone share some sample of code of transaction with fivewin . Thanks
ADO and Lock
Hello I have DBF file AADD (aDbf, {"XXXXX", "L", 1 , 0 }) when I print the Invoice I open the file in in exclusive mode Dbusearea(.F. ,"DBFCDX" , m->E7 + ::cFile ,::oDbfMov:cAlias ,.T. ,.F.) I use the same method with SQL. Regards Maurizio <!-- w --><a class="postlink" href="http://www.nipeservice.com">www.nipeservice.com</a><!-- w -->
ADO and Lock
[quote="nageswaragunupudi":3r9ydpse]The easiest and the most reliable way is to create the invoiceno field as an autoincrement field. Note: Even for DBFs (using DBFCDX) this is the current practice to use autoincrement field. FW functions for ADO make it very easy to implement[/quote:3r9ydpse] Hi Mr. Rao, How Can I define autoincrement field in DBFCDX. Thanks.
ADO and Lock
[code=fw:1w3d98sw]<div class="fw" id="{CB}" style="font-family: monospace;"><br />Hi...<br /><br />In addition <span style="color: #0000ff;">to</span> controlling the row, I check <span style="color: #00C800;">if</span> the <span style="color: #00C800;">new</span> invoice number <span style="color: #0000ff;">exists</span> in the transaction table, since it is feasible that someone consecutive alter table, <span style="color: #00C800;">for</span> which use the following SQL with php :<br /><br /><span style="color: #00C800;">function</span> bloqueaDesbloqueaTablaConsecutivo<span style="color: #000000;">&#40;</span>$conn,$lBloTab<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br /><br />    $cSenEje  = <span style="color: #ff0000;">"UNLOCK TABLES;"</span>;<br />    <span style="color: #00C800;">if</span> <span style="color: #000000;">&#40;</span> $lBloTab == <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />       $cSenEje  = <span style="color: #ff0000;">"LOCK TABLES consecutivos AS sec WRITE, transainventarios  WRITE, conceptosinventarios AS con WRITE;"</span>;<br />    <span style="color: #000000;">&#125;</span>;   <br />  $stmt=$conn->prepare<span style="color: #000000;">&#40;</span>$cSenEje<span style="color: #000000;">&#41;</span>;<br />  $stmt->setFetchMode<span style="color: #000000;">&#40;</span>PDO::<span style="color: #000000;">FETCH_ASSOC</span><span style="color: #000000;">&#41;</span>;<br />    $stmt->execute<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;    <br />    $registros = $stmt->rowCount<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />    unset<span style="color: #000000;">&#40;</span>$stmt<span style="color: #000000;">&#41;</span>; <br />    <br /><span style="color: #000000;">&#125;</span>   <br /><br />Johnson Russi <br /><br /> </div>[/code:1w3d98sw]
ADO and Lock
Instead of using an AutoIncrement field -for the reasons I have argued above on this thread- one way to solve this problem is to create a unique index based on the Invoice No field. When you try to insert a new record with an existing invoice number it will fail. After recovering, have the code continue to iterate until successful. Like I said above, IMHO auto increment fields do not make good invoice numbers. If you ever merge data, replicate, res-structure, move records, you will not have any control over these auto-incremented values and they may reset creating havoc with child-relationships. If you still prefer to use auto-increment field as invoice numbers here is sample code similar to clipper's syntax: [url:onp3c0ox]http&#58;//www&#46;dbase&#46;com/Knowledgebase/dbulletin/bu02_c&#46;htm[/url:onp3c0ox] Hope that helps. Reinaldo.
ADO and Lock
Horizon, [quote:182kpnr9]How Can I define autoincrement field in DBFCDX.[/quote:182kpnr9] Define it with the type "+" James
ADO and Lock
[quote="James Bott":2sy6tb1t]Horizon, [quote:2sy6tb1t]How Can I define autoincrement field in DBFCDX.[/quote:2sy6tb1t] Define it with the type "+" James[/quote:2sy6tb1t] Thank you James. Is it possible to set a number to autoincrement field as a starting number?
ADO and Lock
Hakan, [quote:2plxszwg]Is it possible to set a number to autoincrement field as a starting number?[/quote:2plxszwg] I don't believe there is a command for that. You could try adding one less records than the starting number you want, then doing a table TRUNCATE command (or ZAP if you are using the ADORDD) and see if that works. I suspect it will just start at 1 again. Maybe you could delete all but the last record. Keep in mind the things that Reinaldo mentioned previously in this thread about all the different issues with using autoincrement fields as IDs. The table can end up with new numbers in the field in several circumstances. James Update: Sorry, I was thinking you were asking about SQL instead of DBFCDX. I don't know the answer for DBFCDX as I just discovered there was an autoincrement fieldtype recently myself, so I have not worked with them.
ADO and Lock
[quote="James Bott":3qap0zx0]Hakan, [quote:3qap0zx0]Is it possible to set a number to autoincrement field as a starting number?[/quote:3qap0zx0] I don't believe there is a command for that. You could try adding one less records than the starting number you want, then doing a table TRUNCATE command (or ZAP if you are using the ADORDD) and see if that works. I suspect it will just start at 1 again. Maybe you could delete all but the last record. Keep in mind the things that Reinaldo mentioned previously in this thread about all the different issues with using autoincrement fields as IDs. The table can end up with new numbers in the field in several circumstances. James Update: Sorry, I was thinking you were asking about SQL instead of DBFCDX. I don't know the answer for DBFCDX as I just discovered there was an autoincrement fieldtype recently myself, so I have not worked with them.[/quote:3qap0zx0] Thank you James.
ADO and Lock
[code=fw:2o5jar0p]<div class="fw" id="{CB}" style="font-family: monospace;"><br />DbFieldInfo<span style="color: #000000;">&#40;</span> DBS_COUNTER, <span style="color: #000000;">1</span>, <span style="color: #000000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: #B900B9;">//Set autoincremt to 10</span><br />DbFieldInfo<span style="color: #000000;">&#40;</span> DBS_STEP, <span style="color: #000000;">1</span>, <span style="color: #000000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: #B900B9;">//Set Step to 4</span></div>[/code:2o5jar0p]
ADO and Lock
Biel, [quote:or83td8y]DbFieldInfo( DBS_COUNTER, 1, 10) //Set autoincremt to 10[/quote:or83td8y] I am guessing that sets the next number to be 10? James
ADO and Lock
[quote="James Bott":2wwyvqk6] I am guessing that sets the next number to be 10? James[/quote:2wwyvqk6] James, that is, next number will be 10.
ADO and Lock
Hello everyone; As you see from my previous posts, I do not like auto-increment fields as unique invoice numbers and I have explained why. I've also explained how a unique index on the invoice number can easily and safely solve the problem. On this post I offer some SQL code (ADS compatible) that relies on a RowVersion field type to accomplish the same. This is how I use it on my applications. The idea here is to keep a single sequences table where all sequences are kept. The table fields are "TableName", "FieldName", "Sequence" and "RowVersion". This last field is of type row version. Whenever a new sequences for any given field on a table is needed, simply update the sequence by adding 1 as long as the rowversion field hasn't changed, we can guarantee no one else has changed the field on a race condition. Just like auto-inc fields rowversion fields are maintained by the SQL engine and incremented anytime a record is updated. Here is the code which explains itself a lot better than words: [code=fw:231a9f9o]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #B900B9;">//-------------------------------------------------</span><br /><span style="color: #B900B9;">//</span><br />DECLARE @num INTEGER ;<br />DECLARE @rv INTEGER ;<br />DECLARE @numrows INTEGER ;<br />DECLARE @c CUROSR AS <span style="color: #0000ff;">SELECT</span> <span style="color: #000000;">&#91;</span>sequence<span style="color: #000000;">&#93;</span>, <span style="color: #000000;">&#91;</span>rowversion<span style="color: #000000;">&#93;</span> <span style="color: #0000ff;">FROM</span> sequences <span style="color: #0000ff;">WHERE</span> table = :<span style="color: #000000;">table</span> AND field = :<span style="color: #000000;">field</span>;<br /><br />@numrows = <span style="color: #000000;">0</span> ;<br /><br /><span style="color: #00C800;">WHILE</span> @numrows=<span style="color: #000000;">0</span> <span style="color: #00C800;">DO</span><br /><br />&nbsp; OPEN @c;<br />&nbsp; FETCH @c;<br /><br />&nbsp; @rv   = @c.rowversion ;<br />&nbsp; @num  = @c.rowversion + <span style="color: #000000;">1</span> ;<br />&nbsp; CLOSE @c;<br /><br />&nbsp; <span style="color: #B900B9;">//if rowversion has changed then someone else has updated the record.</span><br />&nbsp; <span style="color: #0000ff;">UPDATE</span> Sequences SET <span style="color: #000000;">&#91;</span>Sequence<span style="color: #000000;">&#93;</span> = @num <span style="color: #0000ff;">WHERE</span> <span style="color: #000000;">&#91;</span>rowversion<span style="color: #000000;">&#93;</span> = @rv;  <br /><br />&nbsp; @numrows = ::<span style="color: #000000;">stmt</span>.UpdateCount ;<br /><br />END;<br /><span style="color: #0000ff;">SELECT</span> @num <span style="color: #0000ff;">FROM</span> system.iota ;<br /><span style="color: #B900B9;">//-------------------------------------------------</span><br /> </div>[/code:231a9f9o] You might have to translate this code into the SQL flavor being used but you get the idea. Reinaldo.
ADO and Lock
I have a similar table that I use to track and generate new ID numbers that I use with DBFs. Since we can use both SQL tables and DBFs in the same app, I am thinking I can continue to use the same DBF which allows locking and thus is a simple solution. I also have a database class that has auto-incrementing using the above table, so I can solve the SQL auto-increment issue too. I think I can implement both of these with the new ADORDD by simply making one change--adding the VIA clause to the sequencing DBF, so that it is uses the DBFCDX RDD. James
ADO and Lock
James, With adordd with SET ADO FORCE LOCK ON no other user or other app (using clipper compatible locking) can alter the table lock or exclusive or record locked hold by you. With this set ON the FILE LOCK, RECORD LOCK, EXCLUSIVE USE are guaranteed.
ADO and Lock
Antonio F. Thanks for confirming that. I have been meaning to ask about it. So, it seems, that my original auto-incrementing system should still work with the ADORDD. I will do some testing to confirm it. Using the ADORDD is too easy, where's the challenge? <!-- s;-) --><img src="{SMILIES_PATH}/icon_wink.gif" alt=";-)" title="Wink" /><!-- s;-) --> Keep working your magic, Antonio. Regards, James
ADO and Lock
Interesting. I use a single file on the server that contains all unique counters ( ie. invoice numbers, client account numbers, etc ). When someone wants to create a new invoice, a very simple call grabs the last number used, increments it, saves it, and gives it to the client machine. This takes a fraction of a second. Over all the years I've used the system, with probably millions of invoices generated on systems from1 to 20 users, I've never had a single duplicate number generated. Tim
ADO and Lock
In a Sql concept,you will do : oRs:Open("select ID FROM TABLE1",oCon) wid:=oRs:Fields("ID"):Value wid:=wid+1 UPDATE TABLE1 SET ID=wid * How can you lock, how are you sure that this code is not execute at the same time from another computer using the same application . ======= In DBF concept , you can open the TABLE1 in EXCLUSIVE and nobody else can modify the record . Any idea ? Thanks
ADO and Lock
Just some ideas. I would prefer the 2nd one. Another alternative in MySql is SELECT ... FOR UPDATE this locks the records. [code=fw:2urumznq]<div class="fw" id="{CB}" style="font-family: monospace;"><br />oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"select ID FROM TABLE1"</span>,oCon<span style="color: #000000;">&#41;</span><br />wid:=oRs:<span style="color: #000000;">Fields</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"ID"</span><span style="color: #000000;">&#41;</span>:<span style="color: #000000;">Value</span> <span style="color: #000000;">+1</span><br />oRs:<span style="color: #000000;">Fields</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"ID"</span><span style="color: #000000;">&#41;</span>:<span style="color: #000000;">Value</span> :=wid<br /><span style="color: #00C800;">try</span><br />&nbsp; oRs:<span style="color: #0000ff;">update</span> <span style="color: #B900B9;">//if it has been changed in underlying data by others it will fail</span><br />catch<br />&nbsp; &nbsp; <span style="color: #00C800;">if</span> &nbsp;oRs:<span style="color: #000000;">Fields</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"ID"</span><span style="color: #000000;">&#41;</span>:<span style="color: #000000;">Value</span> <> wid<br />&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #B900B9;">//update fail</span><br />&nbsp; &nbsp;<span style="color: #00C800;">endif</span><br />end<br />&nbsp;</div>[/code:2urumznq] [code=fw:2urumznq]<div class="fw" id="{CB}" style="font-family: monospace;"><br />oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"select ID FROM TABLE1"</span>,oCon<span style="color: #000000;">&#41;</span><br />wid:=oRs:<span style="color: #000000;">Fields</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"ID"</span><span style="color: #000000;">&#41;</span>:<span style="color: #000000;">Value</span><span style="color: #000000;">+1</span><br /><span style="color: #0000ff;">UPDATE</span> TABLE1 SET <span style="color: #0000ff;">ID</span>=widwhere <span style="color: #0000ff;">ID</span> = wid <span style="color: #000000;">-1</span><br />oRs:<span style="color: #000000;">Resync</span> &nbsp;<span style="color: #B900B9;">//in this table no one can delete records otherwise this might fail</span><br />&nbsp; &nbsp; <span style="color: #00C800;">if</span> &nbsp;oRs:<span style="color: #000000;">Fields</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"ID"</span><span style="color: #000000;">&#41;</span>:<span style="color: #000000;">Value</span> <> wid<br />&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #B900B9;">//update fail</span><br />&nbsp; &nbsp;<span style="color: #00C800;">endif</span><br />&nbsp;</div>[/code:2urumznq]
ADO and MySql
Hi All I a trying to use MySQL and ADO - I have a connection to the database and can open a table but not sure what code to use to add records - according to a wiki page I found called ado-related stuff I can do the following oRs:AddNew() oRs:Fields('code'):Value := 'Test') oRs:Update() That code does not produce any errors but the record is not added the other way is to use a insert statement which I have got to work. Is it worth using AdoRDD ( not sure if it works with xHarbour or where I get it from ) Cheers Colin
ADO and MySql
Hello, Please, see TDataRow class explained in whatsnew.txt. Very good class.
ADO and MySql
Colin Nothing specifically wrong with your addnew() and Update() .. please check how you create your Recordset and I suggest using these parameters : [code=fw:3o04bzri]<div class="fw" id="{CB}" style="font-family: monospace;"><br />oRs := TOleAuto<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>:<span style="color: #00C800;">New</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"ADODB.Recordset"</span> <span style="color: #000000;">&#41;</span><br />oRs:<span style="color: #000000;">CursorType</span>     := <span style="color: #000000;">1</span>        <span style="color: #B900B9;">// opendkeyset</span><br />oRs:<span style="color: #000000;">CursorLocation</span> := <span style="color: #000000;">3</span>        <span style="color: #B900B9;">// local cache</span><br />oRs:<span style="color: #000000;">LockType</span>       := <span style="color: #000000;">3</span>        <span style="color: #B900B9;">// lockoportunistic</span><br /><br />cSql := <span style="color: #ff0000;">"Select * From [YourTable] "</span><br /><br /><span style="color: #00C800;">TRY</span><br />   oRs:<span style="color: #000000;">Open</span><span style="color: #000000;">&#40;</span> cSQL,xCONNECT <span style="color: #000000;">&#41;</span><br />CATCH oErr<br />   <span style="color: #0000ff;">MsgInfo</span><span style="color: #000000;">&#40;</span> <span style="color: #ff0000;">"Error in Opening YOURTABLE table"</span> <span style="color: #000000;">&#41;</span><br />   <span style="color: #00C800;">RETURN</span><span style="color: #000000;">&#40;</span>.F.<span style="color: #000000;">&#41;</span><br />END <span style="color: #00C800;">TRY</span><br /><br />oRs:<span style="color: #000000;">AddNew</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />oRs:<span style="color: #000000;">Fields</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">"YourField"</span><span style="color: #000000;">&#41;</span>:<span style="color: #000000;">Value</span> := <span style="color: #ff0000;">"Test"</span><br />oRs:<span style="color: #0000ff;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /><br /><span style="color: #0000ff;">xBrowse</span><span style="color: #000000;">&#40;</span> oRs <span style="color: #000000;">&#41;</span><br /><br />oRs:<span style="color: #000000;">CLose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br /> </div>[/code:3o04bzri] The above code assumes that you have a Primary key that is auto created... xConnect is your connection string to MySql. Rick Lipkin
ADO and MySql
Thanks Rick - much appreciated. Colin
ADO and decimal numbers
hi I have this code [code=fw:2b7k45tt]<div class="fw" id="{CB}" style="font-family: monospace;"><br /><br />@ <span style="color: #000000;">40</span>, <span style="color: #000000;">10</span> <span style="color: #0000ff;">GET</span> o_get <span style="color: #0000ff;">VAR</span> m_get MEMO <span style="color: #0000ff;">OF</span> <span style="color: #0000ff;">dialog</span> <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">450</span>, <span style="color: #000000;">200</span>   <span style="color: #0000ff;">PIXEL</span><br /><br />oRs := FW_OpenRecordSet<span style="color: #000000;">&#40;</span> oCn, m_Get, <span style="color: #000000;">1</span> <span style="color: #000000;">&#41;</span><br />...<br />@ <span style="color: #000000;">40</span>,<span style="color: #000000;">10</span> <span style="color: #0000ff;">XBROWSE</span> oBrw <span style="color: #0000ff;">SIZE</span> <span style="color: #000000;">-10</span>,<span style="color: #000000;">-50</span> <span style="color: #0000ff;">PIXEL</span> CELL AUTOSORT;<br />RECORDSET oRs <span style="color: #0000ff;">AUTOCOLS</span>;<br /><span style="color: #0000ff;">OF</span> oDlg2    <br /> </div>[/code:2b7k45tt] In m_get I put my Select... (Select * FROM...) XBROWSE shows two decimal numbers but I want four decimal numbers I can not to use PICTURE because SELECT change according to what I write in m_get thank you
ADO and decimal numbers
Ciao , try SET DECIMALS TO 4 Maurizio <!-- w --><a class="postlink" href="http://www.nipeservice.com">www.nipeservice.com</a><!-- w -->
ADO and decimal numbers
Hi ciao Maurizio SET DECIMAL TO is inside at the top of .prg but not work with ADO
ADO and decimal numbers
Please make this modification in your xbrowse.prg: Please locate the following lines in METHOD SetColFromADO(...) [code=fw:wj8iv9yq]<div class="fw" id="{CB}" style="font-family: monospace;"> &nbsp; <span style="color: #00C800;">CASE</span> ASCAN<span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">4</span>, <span style="color: #000000;">5</span>, <span style="color: #000000;">6</span> <span style="color: #000000;">&#125;</span>, nType <span style="color: #000000;">&#41;</span> > <span style="color: #000000;">0</span> &nbsp;<span style="color: #B900B9;">// Single, Double, Currency</span><br />&nbsp; &nbsp; &nbsp; cType &nbsp; &nbsp; &nbsp; &nbsp; := <span style="color: #ff0000;">'N'</span><br />&nbsp; &nbsp; &nbsp; nLen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= oField:<span style="color: #000000;">Precision</span><br />&nbsp; &nbsp; &nbsp; nDec &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= <span style="color: #000000;">2</span><br />&nbsp;</div>[/code:wj8iv9yq] Please change the last line as: [code=fw:wj8iv9yq]<div class="fw" id="{CB}" style="font-family: monospace;"><br />&nbsp; &nbsp; &nbsp; &nbsp;nDec &nbsp;:= Set<span style="color: #000000;">&#40;</span> _SET_DECIMALS <span style="color: #000000;">&#41;</span><br />&nbsp;</div>[/code:wj8iv9yq] Now, in your code SET DECIMALS TO 4 and run your program Please let us know if this is working ok for you.
ADO and decimal numbers
hi Mr Rao thank you I try this in xbrowse.prg [code=fw:shxqfnam]<div class="fw" id="{CB}" style="font-family: monospace;">   <span style="color: #00C800;">CASE</span> ASCAN<span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">4</span>, <span style="color: #000000;">5</span>, <span style="color: #000000;">6</span> <span style="color: #000000;">&#125;</span>, nType <span style="color: #000000;">&#41;</span> > <span style="color: #000000;">0</span>  <span style="color: #B900B9;">// Single, Double, Currency</span><br />      cType         := <span style="color: #ff0000;">'N'</span><br />      nLen          := oField:<span style="color: #000000;">Precision</span><br />      nDec          := Set<span style="color: #000000;">&#40;</span> _SET_DECIMALS <span style="color: #000000;">&#41;</span><br />*     nDec          := <span style="color: #000000;">2</span></div>[/code:shxqfnam] and in my.prg [code=fw:shxqfnam]<div class="fw" id="{CB}" style="font-family: monospace;">   SET DATE ITALIAN<br />    SET DELETED <span style="color: #0000ff;">ON</span><br />    SET CENTURY <span style="color: #0000ff;">ON</span><br />    SET CONFIRM <span style="color: #0000ff;">ON</span><br />    SET DECIMALS <span style="color: #0000ff;">TO</span> <span style="color: #000000;">4</span><br />    SET FIXED <span style="color: #0000ff;">ON</span>   </div>[/code:shxqfnam] Inside file LINK1.RSP there is list of all .obj to compile and I put in xbrowse.obj [code=fw:shxqfnam]<div class="fw" id="{CB}" style="font-family: monospace;"><span style="color: #00C800;">IF</span> NOT ERRORLEVEL <span style="color: #000000;">1</span> <span style="color: #00C800;">IF</span> EXIST *.obj c:\borland\bcc55\bin\ilink32 c0w32 @link1.rsp</div>[/code:shxqfnam] [code=fw:shxqfnam]<div class="fw" id="{CB}" style="font-family: monospace;">...<br />prvmail.obj +<br />sendmail1.obj +<br />sendmail2.obj +<br />interact.obj +<br /><span style="color: #0000ff;">xbrowse</span>.obj +<br />funzio.obj, +<br />MYEXE.exe, + <br />MYEXE.map, ...+</div>[/code:shxqfnam] but in my browse I still get two decimals
ADO and decimal numbers
I Mr Rao in xBrowse i changed oCol:nDataDec in SetColFromADO METHOD [code=fw:1jz3udsy]<div class="fw" id="{CB}" style="font-family: monospace;"><br /><span style="color: #00C800;">if</span> nDec != <span style="color: #00C800;">nil</span><br />*      oCol:<span style="color: #000000;">nDataDec</span>  := <span style="color: #0000ff;">Min</span><span style="color: #000000;">&#40;</span> nDec, <span style="color: #000000;">2</span> <span style="color: #000000;">&#41;</span><br />       oCol:<span style="color: #000000;">nDataDec</span>  :=  nDec <br /><span style="color: #00C800;">endif</span></div>[/code:1jz3udsy] and now works
ADO and decimal numbers
[quote="damianodec":293nk86n]I Mr Rao in xBrowse i changed oCol:nDataDec in SetColFromADO METHOD [code=fw:293nk86n]<div class="fw" id="{CB}" style="font-family: monospace;"><br /><span style="color: #00C800;">if</span> nDec != <span style="color: #00C800;">nil</span><br />*      oCol:<span style="color: #000000;">nDataDec</span>  := <span style="color: #0000ff;">Min</span><span style="color: #000000;">&#40;</span> nDec, <span style="color: #000000;">2</span> <span style="color: #000000;">&#41;</span><br />       oCol:<span style="color: #000000;">nDataDec</span>  :=  nDec <br /><span style="color: #00C800;">endif</span></div>[/code:293nk86n] and now works[/quote:293nk86n] This seems to be code from an older version. Current version is just what you corrected. So my first modification was working for me without problems