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
错误讯息:
Msg 205,Level 16,State 1,Line 1 使用UNION,INTERSECT或EXCEPT运算符组合的所有查询在目标列表中必须具有相同数量的表达式。
注意:两个查询都是单独的。我希望gridview显示一个无法填充列的空白字符串.Chris。
答案 0 :(得分:6)
将第二个select语句更改为:
SELECT BossID, Status, CouponNumber, FK_PrizeID, FK_WinnerID, PrizeName, FirstName, LastName, DOB , '', '' , '', '', '', ''
确保两个查询都返回相同数量的字段
答案 1 :(得分: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,tournamentprizes tp,prizes 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。状态= '有空'
UNION
SELECT LastName,FirstName,DOB,NULL,NULL,BossID,NULL,NULL,NULL,Status,NULL,FK_PrizeID, PrizeName,bRedeemed,CouponNumber,FK_WinnerID
FROM BountyPrizes,Prizes,Players 其中Prizes.PrizeID = BountyPrizes.FK_PrizeID和Players.PlayerID = BountyPrizes.FK_WinnerID
按vtw.tournamentdatetime DESC命令