找回密码
 注册账号

QQ登录

只需一步,快速开始

手机号码,快捷登录

手机号码,快捷登录

初学者课程:T3自学|T6自学|U8自学软件下载课件下载工具下载资料:通资料|U8资料|NC|培训|年结积分规则 | 使用常见问题Q&A
知识库:U8 | | NC | U9 | OA | 政务U8|U9|NCC|NC65|NC65客开|NCC客开新手必读 | 任务 | 快速增金币用友QQ群[微信群]
查看: 4160|回复: 11

[已解决] 请U8 sql 高手帮忙看下语句错在哪里

[复制链接]
发表于 2016-6-19 11:38:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册账号

×
本帖最后由 janse_wang 于 2016-6-20 12:52 编辑

DECLARE @STRCN VARCHAR(8000)
SELECT @STRCN=ISNULL(@STRCN+',','')+ K.[母件编码] FROM
(select
a.BomId as 'BOMID',
c.InvCode as '母件编码',d.cInvName as '母件名称' ,
j.InvCode as '子件编码',h.cInvName as '子件名称',
d.cInvStd as '子件规格',e.cComUnitName as '计量单位',
SUM(F.BaseQtyD) as '基本用量' ,CompScrap as '子件损耗率',
EffBegDate as '子件生效日',EffEndDate as '子件失效日'
from bom_bom as a
join bom_parent as b on a.BomId=b.BomId
join bom_opcomponent as f on b.BomId=f.BomId
join bas_part as c on b.ParentId=c.PartId
join bas_part as j on f.componentId=j.PartId
join Inventory as d on c.InvCode=d.cInvCode
join Inventory as h on j.InvCode=h.cInvCode
join ComputationUnit as e ON h.cComUnitCode =e.cComUnitCode
GROUP BY
a.BomId,
c.InvCode,d.cInvName,
j.InvCode,h.cInvName,
d.cInvStd ,e.cComUnitName,CompScrap,
EffBegDate,EffEndDate) as k
GROUP BY K.[母件编码]
--PRINT(@STRCN)
DECLARE @SQLSTR VARCHAR(8000)
SET @SQLSTR='
SELECT * FROM
(
select
c.InvCode as '母件编码',
j.InvCode as '子件编码',
SUM(F.BaseQtyD) as '基本用量'
from bom_bom as a
join bom_parent as b on a.BomId=b.BomId
join bom_opcomponent as f on b.BomId=f.BomId
join bas_part as c on b.ParentId=c.PartId
join bas_part as j on f.componentId=j.PartId
join Inventory as d on c.InvCode=d.cInvCode
join Inventory as h on j.InvCode=h.cInvCode
join ComputationUnit as e ON h.cComUnitCode =e.cComUnitCode
GROUP BY
c.InvCode,
j.InvCode,
) AS T
PIVOT(MAX(T.[基本用量])
FOR T.[母件编码] IN ( '+@STRCN+' ) ) AS W'
--PRINT(@SQLSTR)
EXEC(@SQLSTR)
 楼主| 发表于 2016-6-19 11:41:24 | 显示全部楼层
提示PIVOT(MAX(T.[基本用量])
FOR T.[母件编码] IN ( '+@STRCN+' ) ) AS W' 附近错误
回复 点赞 拍砖

使用道具 举报

发表于 2016-6-19 11:54:43 | 显示全部楼层
  1. DECLARE @STRCN VARCHAR(8000)
  2. SELECT @STRCN=ISNULL(@STRCN+',','')+ K.[母件编码] FROM
  3. (select
  4. a.BomId as 'BOMID',
  5. c.InvCode as '母件编码',d.cInvName as '母件名称' ,
  6. j.InvCode as '子件编码',h.cInvName as '子件名称',
  7. d.cInvStd as '子件规格',e.cComUnitName as '计量单位',
  8. SUM(F.BaseQtyD) as '基本用量' ,CompScrap as '子件损耗率',
  9. EffBegDate as '子件生效日',EffEndDate as '子件失效日'
  10. from bom_bom as a
  11. join bom_parent as b on a.BomId=b.BomId
  12. join bom_opcomponent as f on b.BomId=f.BomId
  13. join bas_part as c on b.ParentId=c.PartId
  14. join bas_part as j on f.componentId=j.PartId
  15. join Inventory as d on c.InvCode=d.cInvCode
  16. join Inventory as h on j.InvCode=h.cInvCode
  17. join ComputationUnit as e ON h.cComUnitCode =e.cComUnitCode
  18. GROUP BY
  19. a.BomId,
  20. c.InvCode,d.cInvName,
  21. j.InvCode,h.cInvName,
  22. d.cInvStd ,e.cComUnitName,CompScrap,
  23. EffBegDate,EffEndDate) as k
  24. GROUP BY K.[母件编码]
  25. --PRINT(@STRCN)
  26. DECLARE @SQLSTR VARCHAR(8000)
  27. SET @SQLSTR='
  28. SELECT * FROM
  29. (
  30. select
  31. c.InvCode as ''母件编码'',
  32. j.InvCode as ''子件编码'',
  33. SUM(F.BaseQtyD) as ''基本用量''
  34. from bom_bom as a
  35. join bom_parent as b on a.BomId=b.BomId
  36. join bom_opcomponent as f on b.BomId=f.BomId
  37. join bas_part as c on b.ParentId=c.PartId
  38. join bas_part as j on f.componentId=j.PartId
  39. join Inventory as d on c.InvCode=d.cInvCode
  40. join Inventory as h on j.InvCode=h.cInvCode
  41. join ComputationUnit as e ON h.cComUnitCode =e.cComUnitCode
  42. GROUP BY
  43. c.InvCode,
  44. j.InvCode,
  45. ) AS T
  46. PIVOT(MAX(T.[基本用量])
  47. FOR T.[母件编码] IN ( '+@STRCN+' ) ) AS W'
  48. --PRINT(@SQLSTR)
  49. EXEC(@SQLSTR)
复制代码

点评

问题依旧 [Err] 42000 - [SQL Server]'母件编码' 附近有语法错误。  详情 回复 发表于 2016-6-19 12:23
回复 点赞 拍砖

使用道具 举报

 楼主| 发表于 2016-6-19 12:18:17 | 显示全部楼层
[Err] 42000 - [SQL Server]')' 附近有语法错误。
回复 点赞 拍砖

使用道具 举报

 楼主| 发表于 2016-6-19 12:23:32 | 显示全部楼层

问题依旧 [Err] 42000 - [SQL Server]'母件编码' 附近有语法错误。
回复 点赞 拍砖

使用道具 举报

发表于 2016-6-19 13:31:15 | 显示全部楼层
你前面的变量@STRCN做下处理,然后查询字段AS也改下,最后参照效果如下
  1. SELECT * FROM
  2. (select c.InvCode as [母件编码],j.InvCode as [子件编码],SUM(F.BaseQtyD) as [基本用量] from bom_bom as a
  3. join bom_parent as b on a.BomId=b.BomId
  4. join bom_opcomponent as f on b.BomId=f.BomId
  5. join bas_part as c on b.ParentId=c.PartId
  6. join bas_part as j on f.componentId=j.PartId
  7. join Inventory as d on c.InvCode=d.cInvCode
  8. join Inventory as h on j.InvCode=h.cInvCode
  9. join ComputationUnit as e ON h.cComUnitCode =e.cComUnitCode
  10. GROUP BY
  11. c.InvCode,
  12. j.InvCode
  13. ) T
  14. PIVOT(MAX([基本用量])
  15. FOR [母件编码] IN ([0301],[0337]) ) W
复制代码

点评

感谢,已解决!!!!!!!!!!  详情 回复 发表于 2016-6-19 14:54
回复 点赞 拍砖

使用道具 举报

 楼主| 发表于 2016-6-19 14:54:11 | 显示全部楼层
jojo_bj 发表于 2016-6-19 13:31
你前面的变量@STRCN做下处理,然后查询字段AS也改下,最后参照效果如下

感谢,已解决!!!!!!!!!!
回复 点赞 拍砖

使用道具 举报

发表于 2016-6-19 20:45:26 | 显示全部楼层
厉害厉害,学习了。
回复 点赞 拍砖

使用道具 举报

  • 打卡等级:偶尔看看
  • 打卡总天数:30
  • 打卡月天数:20
  • 打卡总奖励:79
  • 最近打卡:2024-11-22 07:51:15
发表于 2016-6-20 09:06:00 | 显示全部楼层
兔神真是厉害的不要不要的
回复 点赞 拍砖

使用道具 举报

发表于 2016-6-21 10:19:51 | 显示全部楼层
学习了
回复 点赞 拍砖

使用道具 举报

发表于 2023-10-25 15:08:36 | 显示全部楼层
这个是查询bom的么?
回复 点赞 拍砖

使用道具 举报

  • 打卡等级:初来乍到
  • 打卡总天数:13
  • 打卡月天数:13
  • 打卡总奖励:34
  • 最近打卡:2024-11-22 07:58:35
发表于 2023-11-2 15:39:33 | 显示全部楼层
认真学习下
回复 点赞 拍砖

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

QQ|站长微信|Archiver|手机版|小黑屋|用友之家 ( 蜀ICP备07505338号|51072502110008 )

GMT+8, 2024-11-23 08:22 , Processed in 0.054045 second(s), 9 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表