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

小弟在下有礼了
SQL code

SELECT pkd.ID,
       Convert(varchar(10),pkl.ViewDate,111)  as ViewTime,
       CONVERT(VARCHAR, pkd.InitialDate) as UploadTime, 
       pkd.ProductLine as ProductLine, 
       pkd.Model as model,
       pkd.SerialNo as SerialNo,
    begin
        select account,
        case when (account ! ='')
        then
            (select account from NTUser where NTUser.[ID] = pkl.viewBy) as UserAccount, 
            (select name from UserSite u,site s where u.siteid=s.id) as sitename,
            'big' as UserType,
        else
            (select account from member where member.[ID] = pkl.viewBy) as UserAccount, 
            (select country from UserSite u,regioncountry c where u.siteid=c.siteID) as sitename,
            'small' as UserType,
        end
        from NTUser,
    end
 FROM pkbknowledgedetail pkd,PKBViewLog pkl
 WHERE Status = 'A' and pkl.KnowLedgeID = pkd.[ID] and viewBy='ASfde0ea4b-4fbf-41af-b4ae-78215f295cbf' 



小弟不胜感激啊            




求大牛门帮忙看下 错误如下:


消息 156,级别 15,状态 1,第 7 行
Incorrect syntax near the keyword 'begin'.
消息 156,级别 15,状态 1,第 11 行
Incorrect syntax near the keyword 'as'.
消息 156,级别 15,状态 1,第 12 行
Incorrect syntax near the keyword 'as'.
消息 156,级别 15,状态 1,第 15 行
Incorrect syntax near the keyword 'as'.
消息 156,级别 15,状态 1,第 16 行
Incorrect syntax near the keyword 'as'.


大致表的意思说下吧 就是 传入 一个viewby,这个ViewBy在PKBViewLog里 各个关系就是根据ViewBy 可以查看KnowLedgeID 这个ID和pkbknowledgedetail的ID对应的

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

建议你提供详细的资料:
例如表的结构,表之间的关系,测试数据,相关算法及需要的结果。
这样有助于我们理解你的意思,更主要的是能尽快让你获得答案或解决问题的方法。

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

SELECT pkd.ID,
       Convert(varchar(10),pkl.ViewDate,111)  as ViewTime,
       CONVERT(VARCHAR, pkd.InitialDate) as UploadTime, 
       pkd.ProductLine as ProductLine, 
       pkd.Model as model,
       pkd.SerialNo as SerialNo,???从哪儿查??后面的呢?
    begin
        select account,
        case when (account ! ='')
        then
            (select account from NTUser where NTUser.[ID] = pkl.viewBy) as UserAccount, 
            (select name from UserSite u,site s where u.siteid=s.id) as sitename,
            'big' as UserType--都好多余
        else
            (select account from member where member.[ID] = pkl.viewBy) as UserAccount, 
            (select country from UserSite u,regioncountry c where u.siteid=c.siteID) as sitename,
            'small' as UserType,
        end
        from NTUser,
    end
 FROM pkbknowledgedetail pkd,PKBViewLog pkl
 WHERE Status = 'A' and pkl.KnowLedgeID = pkd.[ID] and viewBy='ASfde0ea4b-4fbf-41af-b4ae-78215f295cbf' 


这个错误太多了,给测试数据和结果吧,不带这么写的

------解决方案--------------------
不带这么写的,你说出来有哪些东西,想干什么,也许会有更好的解决方法。
------解决方案--------------------
楼主,小弟我投降了
------解决方案--------------------

------解决方案--------------------
支持楼主--精神
------解决方案--------------------
探讨

引用:
楼主,小弟我投降了



亲 我也想把数据库发出来。。。。可是这个不是我自己的项目啊。。。是公司的。。。我现在纠结啊

------解决方案--------------------
SQL SERVER 2000?2005?2008?

SQL code

;WITH m1 AS 
( SELECT  account ,
  (SELECT account FROM NTUser WHERE NTUser.[ID] = pkl.viewBy) AS UserAccount ,
  (SELECT name FROM UserSite u ,site s WHERE u.siteid = s.id) AS sitename ,
   'big' AS UserType FROM NTUser WHERE account ! = ''
   UNION ALL
  SELECT  account ,
  (SELECT account FROM member WHERE member.[ID] = pkl.viewBy),
  (SELECT country FROM UserSite u ,regionc