Solved

SQL Server 2000 query

Posted on 2014-01-15
3
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

737 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