<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[My Visual Database — Using AND in a sql statement]]></title>
		<link>https://myvisualdatabase.com/forum/viewtopic.php?id=6320</link>
		<atom:link href="https://myvisualdatabase.com/forum/extern.php?action=feed&amp;tid=6320&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Using AND in a sql statement.]]></description>
		<lastBuildDate>Sun, 31 May 2020 04:18:16 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Using AND in a sql statement]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=36416#p36416</link>
			<description><![CDATA[<p>Thank you sibprogsistem,</p><p>As you suggested, I separated the two fields into two statements and that works fine.</p>]]></description>
			<author><![CDATA[null@example.com (CDB)]]></author>
			<pubDate>Sun, 31 May 2020 04:18:16 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=36416#p36416</guid>
		</item>
		<item>
			<title><![CDATA[Re: Using AND in a sql statement]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=36414#p36414</link>
			<description><![CDATA[<p>.</p>]]></description>
			<author><![CDATA[null@example.com (sibprogsistem)]]></author>
			<pubDate>Sat, 30 May 2020 21:27:19 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=36414#p36414</guid>
		</item>
		<item>
			<title><![CDATA[Using AND in a sql statement]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=36412#p36412</link>
			<description><![CDATA[<p>I have written a procedure that is used to receipt a complete order assuming there are no discrepancies. The amount of items on the order can vary from 1........ Many.</p><br /><p>The plain SQL tested in SQL Studio is:</p><div class="codebox"><pre><code>UPDATE orders SET receivedQty = &#039;10&#039;, receivedDate = date(&#039;now&#039;) WHERE orders.orderRef = &#039;REQ 277/12&#039; AND orders.id = 3;</code></pre></div><br /><p>Now I have converted it to the SQLExecute statement below, but it is not working, it never updates the database. Does MVD work with logical ANDs in the SQL statements? Or will I have to write the above SQL as two lines of code?</p><br /><div class="codebox"><pre><code>procedure receiveOrder_btnReceiveAll_PO_OnClick (Sender: TObject; var Cancel: boolean);
var
 indx, received : integer;
 s :  string;
 ds : TDataset;
begin


   indx := 0; {index counter for iterating through available rows of DB grid}

   { Get the Order ID from Orders table for all matching purchase orders, place result into the dataset}
   sqlQuery(&#039;SELECT orders.id FROM orders WHERE orders.orderRef = &quot;&#039; +receiveOrder.cmbPO.Text+&#039;&quot;&#039;, ds);

   ds.First; {Make sure we are at the beginning of the dataset}

   {All the work is done here.
    Assign the orders.id to &#039;S&#039;, copy qty ordered to qty received store in &#039;received&#039; then update the records in ORDERS
    with &#039;received Qty&#039; the Date received matching the order Id and PO number}
   while not ds.EOF do
   begin
       s := ds.FieldByName(&#039;ID&#039;).asString;
       received := strToInt(receiveOrder.tgReceiveOrder.Cells[3,indx]);
       sqlexecute(&#039;UPDATE orders SET receivedQty = &#039;+ intToStr(received) +&#039;, receivedDate = date(&#039;&#039;now&#039;&#039;) WHERE (orders.orderRef = &quot;&#039;+ receiveOrder.cmbPO.Text +&#039;&quot;) AND (+ orders.id = &quot;&#039;+ s +&#039;&quot;)&#039;);
       showmessage(&#039;order Id &#039; + s); // temporary debug check to make sure order.id is correct
       ds.next; {move to the next record}
       indx := indx + 1; {increment counter for the tablegrid row.}
   end;

   ds.Close;  {Close the dataset and free the database}
   ds.Free;
   showMessage(&#039;Complete Purchase Order Receipted&#039;);

end;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (CDB)]]></author>
			<pubDate>Sat, 30 May 2020 11:30:01 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=36412#p36412</guid>
		</item>
	</channel>
</rss>
