0
select distinct vtw.lastname, vtw.firstname, vtw.dob, vtw.clubnumber, vtw.tournamentname, vtw.BossTournamentID, vtw.tournamentdatetime, vtw.tournamentid, tp.tournamentprizeid, tp.status, tp.place, p.prizeid,p.prizename, tp.bRedeemed, tp.CouponNumber

from vwTournamentWinners vtw, tournamentprizes tp, prizes p

where vtw.fk_tournamentid=tp.fk_tournamentid and vtw.fk_playerid=tp.fk_winnerid and tp.fk_prizeid=p.prizeid and vtw.tournamentdatetime between '8/10/2013' and '8/10/2013' and tp.status='Available'

UNION

SELECT BossID, Status, CouponNumber, FK_PrizeID, FK_WinnerID, PrizeName, FirstName, LastName, DOB 
FROM BountyPrizes, Prizes, Players
where Prizes.PrizeID=BountyPrizes.FK_PrizeID and Players.PlayerID=BountyPrizes.FK_WinnerID

order by vtw.tournamentdatetime DESC

Error message:

Msg 205, Level 16, State 1, Line 1 All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.

Note: both queries work individually. I want the gridview to display a blank string where the columns cannot be filled in. Chris.

4

2 回答 2

6

将第二个 select 语句更改为:

SELECT BossID, Status, CouponNumber, FK_PrizeID, FK_WinnerID, PrizeName, FirstName, LastName, DOB , '', '' , '', '', '', ''

确保两个查询返回相同数量的字段

于 2013-08-10T09:43:17.270 回答
0

选择不同的 vtw.lastname, vtw.firstname, vtw.dob, vtw.clubnumber, vtw.tournamentname, vtw.BossTournamentID, vtw.tournamentdatetime, vtw.tournamentid, tp.tournamentprizeid, tp.status, tp.place, p.prizeid, p.prizename, tp.bRedeemed, tp.CouponNumber, NULL

来自 vwTournamentWinners vtw,锦标赛奖品 tp,奖品 p

其中 vtw.fk_tournamentid=tp.fk_tournamentid 和 vtw.fk_playerid=tp.fk_winnerid 和 tp.fk_prizeid=p.prizeid 和 vtw.tournamentdatetime 在 '8/10/2013' 和 '8/10/2013' 和 tp.status=' 之间可用的'

联盟

选择姓氏、名字、出生日期、空值、空值、BossID、空值、空值、空值、状态、空值、FK_PrizeID、PrizeName、bRedeemed、CouponNumber、FK_WinnerID

FROM BountyPrizes, Prizes, Players where Prizes.PrizeID=BountyPrizes.FK_PrizeID and Players.PlayerID=BountyPrizes.FK_WinnerID

按 vtw.tournamentdatetime DESC 排序

于 2013-08-10T09:47:55.597 回答