469,950 Members | 1,822 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

multi rows SELECT

Cshrek
8
helo,
i have no problems executing that query, but it only returnes the last row from each table.
how would i be able to retrive all the rows?

ALTER PROCEDURE dbo.AccountTrakingSELECT

@From smallDateTime,
@To smallDateTime


AS

DECLARE @VolID int

DECLARE @TransactionID int

SELECT @VolID = VolID, @TransactionID = TransactionID FROM Transactions WHERE TransactionTime BETWEEN @From AND @To

SELECT * FROM Transactions WHERE TransactionID = @TransactionID

SELECT VolFrstNameEN, VolLastNameEN FROM VolMain WHERE VolID= @VolID

RETURN
GO
Jul 19 '07 #1
2 1343
srinit
43
helo,
i have no problems executing that query, but it only returnes the last row from each table.
how would i be able to retrive all the rows?

ALTER PROCEDURE dbo.AccountTrakingSELECT

@From smallDateTime,
@To smallDateTime


AS

DECLARE @VolID int

DECLARE @TransactionID int

SELECT @VolID = VolID, @TransactionID = VolIDFROM Transactions WHERE TransactionTime BETWEEN @From AND @To

SELECT * FROM Transactions WHERE TransactionID = @TransactionID

SELECT VolFrstNameEN, VolLastNameEN FROM VolMain WHERE VolID= @VolID

RETURN
GO

hi
I am not clear with your code. try with this code .this is not exactly suit for ur requirement but this idea will help you

[code]
declare cur1 for select VolID from Transactions WHERE TransactionTime BETWEEN @From AND @To
open cur1
fetch next from cur1 into @VolID
while @@fetch_status=0
begin
SELECT VolFrstNameEN, VolLastNameEN FROM VolMain WHERE VolID= @VolID
fetch next from cur1 into @VolID
end
Jul 19 '07 #2
Cshrek
8
hey, thanks.
wehn i try to run that code:

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

ALTER PROCEDURE dbo.AccountTrakingSELECT

@From smallDateTime,

@To smallDateTime

AS

DECLARE @VolID int

DECLARE @TransactionID int

declare cur1 for select VolID from Transactions WHERE TransactionTime BETWEEN @From AND @To
open cur1
fetch next from cur1 into @VolID
while @@fetch_status=0
begin
SELECT VolFrstNameEN, VolLastNameEN FROM VolMain WHERE VolID= @VolID
fetch next from cur1 into @VolID
end

--------------------------------------------------------------------------------------------------------------
it all seems to be good, but i get that error:

"Msg 156, Level 15, State 1, Procedure AccountTrakingSELECT, Line 22
Incorrect syntax near the keyword 'for'."

and i defently have no idea what is that mean? or what am i doing worng?

appriciate your help.
Jul 19 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Gordon | last post: by
reply views Thread by WhiteWizard | last post: by
1 post views Thread by =?Utf-8?B?R2lkaQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.