Solved

SQL Server 2000 query

Posted on 2014-01-15
3
265 Views
Last Modified: 2014-01-16
First, I must use a SQL Server 2000 database.  

I have a dataset that looks like this:

supplierid      deliverydate      familyid      productid      QtyOrdered
8010382      2014-01-20 00:00:00.000            30898      40496      2
8010382      2014-01-20 00:00:00.000            30908      40506      4
8010382      2014-01-20 00:00:00.000            30909      40507      2
8010382      2014-01-20 00:00:00.000            30910      40508      3
8010382      2014-01-20 00:00:00.000            30913      40511      2
8010382      2014-01-20 00:00:00.000            31513      41126      2
8010382      2014-01-20 00:00:00.000            31514      41127      2
8010382      2014-01-20 00:00:00.000            31557      41171      2
8010382      2014-01-20 00:00:00.000            32119      41775      5
8010476      2014-01-19 00:00:00.000            30993      40591      1
8010453      2014-01-19 00:00:00.000            31034      40632      1
8010453      2014-01-19 00:00:00.000            31035      40633      1
8010453      2014-01-19 00:00:00.000            31045      40643      1

I need to write a file for each distinct supplierid.  I cannot use a cursor.  

For example I need 3 text files..one for 8010382, 8010476 and 8010453.    I need to read all the records for 8010382 and write to a file, then do the same for the other two.

How can I loop through this table without using a cursor.  I would normally use a CTE, but I cannot because of the version of SQl I must use.

Anybody have any ideas.

Thanks.
0
Comment
Question by:sherbug1015
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39783696
ok this what you can do

declare @MinID BIGINT
DECLARE @maxID BINGT

SELECT @minID = MIN(supplierID) FRom <yourTable>
SELECT @MaxID = mAX(supplierID) from <your table>
WHILE @minID <= @maxID
BEGIN

-- Write to File using @minID

SELECT TOP 1 @minID = SupplierID 
FROM <your Table>
where supplierID > @minID
ORDER BY supplierID 


END

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39783898
how do you actually "plan" to "write" to a file?
0
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39783980
@Hengel, if the question is for me, I left that part to user, as he might already have the command or else a I could have filled it up with a simple BCP out.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question