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 2005 Forums
 Transact-SQL (2005)
 Combine 2 SELECT

Author  Topic 

irmorteza
Starting Member

8 Posts

Posted - 2010-08-23 : 10:14:12
Hi

I used cursor loop , and in each loop do select. but this selects are seperates from each other and "union statement" not work.

my question is how can i combines select results in one in this situation .

best regard. morteza


DECLARE @idBook int -- used for file name
DECLARE db_cursor CURSOR FOR
SELECT id
FROM Book
WHERE (idMember = 5)
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @idBook
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @idBook as idBook, tb1.id, member.username, type.type, tb1.budget
FROM tb1 INNER JOIN
type ON tb1.idType = type.id INNER JOIN
member ON tb1.idMember = member.id
WHERE (tb1.active = 0) AND (tb1.idBook = @idBook)
FETCH NEXT FROM db_cursor INTO @idBook
END
CLOSE db_cursor
DEALLOCATE db_cursor

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-23 : 10:27:20
[code]SELECT b.id AS idBook,
t.id,
m.username,
y.[type],
t.budget
FROM Book AS b
INNER JOIN tb1 AS t ON t.idBook = b.id
AND t.active = 0
INNER JOIN [Type] AS y ON y.id = t.idType
INNER JOIN member AS m ON m.id = t.idMember
WHERE b.idMember = 5[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

irmorteza
Starting Member

8 Posts

Posted - 2010-08-23 : 11:15:40
thancks Peso
i did this before but return nothing in your way
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-23 : 14:27:46
Then nothing is returned with your cursor code either?


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -