Solved

SQL Server 2000 query

Posted on 2014-01-15
3
263 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 142

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now