Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server Select Statements with Multiple Rowcounts
    primarykey
    data
    text
    <p>Is there a way to call column from one table and sort by a date from another table and does this for three numbers 5,6,99? i have an example that may clarify. This is an interesting procedure that we are currently stuck on at a plant.</p> <p>---this is example tables of what it is ----</p> <p>table a</p> <pre> 6 queued (there are ten of these with ID's of course) 5 queued (there are 8 with id's ) 99 queued (there are 7 with id's) </pre> <p>*<strong><em>Table B example of what it is</em>**<em>*</em></strong></p> <p>table b</p> <p>(the exact qty doesnt match, its an example. Where there is an ID in table A; Table B has an ID matching to equal each other. )</p> <pre> id 11/1/2013 10:00:01 id 11/1/2013 10:00:02 id 11/1/2013 10:00:03 id 11/1/2013 10:00:04 id 11/1/2013 10:00:05 id 11/1/2013 10:00:06 id 11/1/2013 10:00:07 id 11/1/2013 10:00:08 id 11/1/2013 10:00:09 id 11/1/2013 10:00:10 id 11/1/2013 10:00:11 id 11/1/2013 10:00:12 id 11/1/2013 10:00:13 id 11/1/2013 10:00:14 id 11/1/2013 10:00:15 id 11/1/2013 10:00:16 id 11/1/2013 10:00:17 id 11/1/2013 10:00:18 id 11/1/2013 10:00:19 id 11/1/2013 10:00:20 </pre> <p>*<strong><em>The form of what it should be NOTE</em> I am displaying the date to show you the order, but in reality the time does not appear its behind the scenes*<em>*</em>**<em>*</em>*</strong></p> <p>Form</p> <pre> 6 id 11/1/2013 10:00:05 6 id 11/1/2013 10:00:06 6 id 11/1/2013 10:00:07 6 id 11/1/2013 10:00:08 6 id 11/1/2013 10:00:09 6 id 11/1/2013 10:00:10 5 id 11/1/2013 10:00:02 5 id 11/1/2013 10:00:03 5 id 11/1/2013 10:00:04 5 id 11/1/2013 10:00:11 5 id 11/1/2013 10:00:13 5 id 11/1/2013 10:00:17 99 id 11/1/2013 10:00:01 99 id 11/1/2013 10:00:12 99 id 11/1/2013 10:00:14 99 id 11/1/2013 10:00:15 99 id 11/1/2013 10:00:16 99 id 11/1/2013 10:00:18 </pre> <p>The VB doesnt need to be changed. It works in other procedures and is happy running as it should. I just need the right order to appear in the form. Does anyone know how to do this?</p> <p>SQL:</p> <pre><code> ALTER PROC [Controls].[spBatch] @Status varchar output ,@RoasterNumber int output ,@RoastProfile int output ,@ChargeWeight float output ,@SuperSackID int output AS SET NOCOUNT ON DECLARE @RETURN int select Top 6 * from wip.RoasterQueueSequence RQS inner join wip.schedule s on s.fk_roasterqueuesequenceid = RQS.PK_RoasterQueueSequenceID where rqs.Status = 'Queued' and rqs.PK_RoasterQueueSequenceID = s.FK_RoasterQueueSequenceID and rqs.RoasterNumber = 6 order by s.publishedstartdatetime asc SELECT @RETURN = @@rowcount FROM WIP.RoasterQueueSequence WHERE Roasternumber = 6 select Top 6 * from wip.RoasterQueueSequence RQS inner join wip.schedule s on s.fk_roasterqueuesequenceid = RQS.PK_RoasterQueueSequenceID where rqs.Status = 'Queued' and rqs.PK_RoasterQueueSequenceID = s.FK_RoasterQueueSequenceID and rqs.RoasterNumber = 5 order by s.publishedstartdatetime asc SELECT @RETURN2 = @@rowcount FROM WIP.RoasterQueueSequence WHERE Roasternumber = 5 select Top 6 * from wip.RoasterQueueSequence RQS inner join wip.schedule s on s.fk_roasterqueuesequenceid = RQS.PK_RoasterQueueSequenceID where rqs.Status = 'Queued' and rqs.PK_RoasterQueueSequenceID = s.FK_RoasterQueueSequenceID and rqs.RoasterNumber = 99 order by s.publishedstartdatetime asc SELECT @RETURN3 = @@rowcount FROM WIP.RoasterQueueSequence WHERE Roasternumber = 99 set @TotalRows = @RETURN + @RETURN2 + @RETURN3 --set @TotalRows = @@rowcount return @TotalRows </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload