Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Assign each row of select results to sp parameters

Author  Topic 

kchrist
Starting Member

2 Posts

Posted - 2005-05-16 : 11:14:41
I want to assign each row of select results to sp parameters.

For example i want to assign the value AttachmentNameUnique from the first row of

SELECT POAttachment.AttachmentNameUnique, POAttachment.POID, POAttachment.POAttachmentID
FROM PO INNER JOIN
POAttachment ON PO.POID = POAttachment.POID
WHERE (PO.POID = 7514)

AttachmentNameUnique POID POAttachmentID
Test.txt 7514 3819
Test1.txt 7514 3820

to Att1

and the value AttachmentNameUnique from the second row

to Att2.

-------------------------------------------------------

Any idea?

Kristen
Test

22859 Posts

Posted - 2005-05-19 : 06:57:20
[code]
DECLARE @intRowCount int,
@Att1 int,
@Att2 int
SELECT @intRowCount = 1
SELECT @Att1 = CASE WHEN @intRowCount = 1 THEN AttachmentNameUnique ELSE @Att1,
@Att2 = CASE WHEN @intRowCount = 2 THEN AttachmentNameUnique ELSE @Att2,
@intRowCount = @intRowCount + 1
FROM PO
INNER JOIN POAttachment
ON PO.POID = POAttachment.POID
WHERE (PO.POID = 7514)
[/code]
You will presumably need an ORDER BY for this to make sense?

I haven't tested this, so no idea if it actually works, but if not it might need an UPDATE statement instead.

Kristen
Go to Top of Page
   

- Advertisement -