日期:2014-05-18  浏览次数:20515 次

从视图中获取数据出问题
该视图的sql语句如下:
SQL code

SELECT     mb.MBID, m.MName, t.TName, c.CName, mb.SerialNum, mb.State, mb.DeliveryNum, CONVERT(varchar(100), mb.SendDate, 23) AS SendDate, CONVERT(varchar(100), 
                      mb.BackDate, 23) AS BackDate, mb.Remark
FROM         dbo.MachineBroken AS mb INNER JOIN
                      dbo.Machine AS m ON mb.MBID = m.MID INNER JOIN
                      dbo.Type AS t ON m.TID = t.TID INNER JOIN
                      dbo.Class AS c ON t.CID = c.CID
WHERE     (mb.IsBack = 0)


单独运行该视图的时候没有数据显示(表中所有数据的IsBack列值都为True,该列类型为bit),但从视图中获取数据时(运行“select * from View_MachineBrokenDetail”)却有数据显示,这是什么原因呢?

------解决方案--------------------
SQL code

SELECT    
 mb.MBID, m.MName, t.TName, c.CName, mb.SerialNum, mb.State,
 mb.DeliveryNum, CONVERT(varchar(100), mb.SendDate, 23) AS SendDate, 
 CONVERT(varchar(100), 
                      mb.BackDate, 23) AS BackDate, mb.Remark
FROM         dbo.MachineBroken AS mb INNER JOIN
                      dbo.Machine AS m ON mb.MBID = m.MID 
                      INNER JOIN
                      dbo.Type AS t ON mb.TID = t.TID 
                      INNER JOIN
                      dbo.Class AS c ON mb.CID = c.CID
WHERE     (mb.IsBack = 0)

try
感觉你的关联有问题,你还是一个表一个表的理清了吧