SQL简单问题……

kyle_huang 2011-12-16 12:47:28
小弟刚学SQL,很多地方不明白,求前辈支支招,谢谢了。

写了个存储过程,如下:
-------------------------------------------------------------------
if object_id('test') is not null --一二句判断存储过程是否存在
drop procedure test
go --批处理,上下批有关系的时候go不能省略
create procedure test --创建存储过程
@ID varchar(50) --输入
as
select '商品ID' = d_Goods.Id, '商品PersonCode' = d_Goods.PersonCode, '商品FullName' = d_Goods.FullName,
'仓库ID' = d_Stock.ID, '仓库PersonCode' = d_Stock.PerSonCode, '仓库FullName' = d_Stock.FullName,
'库存数量' = sum(d_StockGoods.Num), '库存金额' = sum(d_StockGoods.Amount)
from D_Stock inner join d_StockGoods on d_StockGoods.sId = D_Stock.Id
inner join d_Goods on d_StockGoods.gID = d_Goods.ID and d_Goods.Id like @ID+'%'
group by d_Goods.Id, d_Goods.PersonCode, d_Goods.FullName, d_Stock.ID, d_Stock.PerSonCode, d_Stock.FullName
go
execute test '00001'
-------------------------------------------------------------------
得到的效果是:(传入参数:商品ID,返回数据:该商品在各个仓库中的分布情况)

商品ID 商品PersonCode 商品FullName 仓库ID 仓库PersonCode 仓库FullName 库存数量 库存金额
-------------------------------------------------------------------------------------------------
0000100001 KB00001 康柏 00001 00001 caigou 8 8
0000100001 KB00001 康柏 00002 00002 qita 100 1000
0000100002 HP00002 惠普001 00002 00002 qita 10 80
-------------------------------------------------------------------------------------------------
但是,这不是我想要的效果,我想要的是:传入参数ID 00001,得到的应该是:

商品ID 商品PersonCode 商品FullName 仓库ID 仓库PersonCode 仓库FullName 库存数量 库存金额
-------------------------------------------------------------------------------------------------
00001 HP00001 惠普 00001 00001 caigou 8 8

(-----接着上面的----) 仓库ID 仓库PersonCode 仓库FullName 库存数量 库存金额
-----------------------------------------------------
00002 00002 qita 110 1080
-----------------------------------------------------
-------------------------------分割线---------------------------------------

00001与0000100001、0000100002的关系是(有个pID,0000100001的pID是00001),也就是我输入00001的时候,出现是上面的。不知道我说清楚没有,或者我上面的SQL语句有问题么。

求前辈帮忙,在此谢。
...全文
78 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
--小F-- 2011-12-16
  • 打赏
  • 举报
回复
create procedure test 
@ID varchar(50)
as
select '商品ID' = d_Goods.Id, '商品PersonCode' = d_Goods.PersonCode, '商品FullName' = d_Goods.FullName,
'仓库ID' = d_Stock.ID, '仓库PersonCode' = d_Stock.PerSonCode, '仓库FullName' = d_Stock.FullName,
'库存数量' = sum(d_StockGoods.Num), '库存金额' = sum(d_StockGoods.Amount)
from D_Stock inner join d_StockGoods on d_StockGoods.sId = D_Stock.Id
inner join d_Goods on d_StockGoods.gID = d_Goods.ID and pId=@ID group by d_Goods.Id, d_Goods.PersonCode, d_Goods.FullName, d_Stock.ID, d_Stock.PerSonCode, d_Stock.FullName
go
execute test '00001'
pengxuan 2011-12-16
  • 打赏
  • 举报
回复

if object_id('test') is not null --一二句判断存储过程是否存在
drop procedure test
go --批处理,上下批有关系的时候go不能省略
create procedure test --创建存储过程
@ID varchar(50) --输入
as
select '商品ID' = d_Goods.Id, '商品PersonCode' = d_Goods.PersonCode, '商品FullName' = d_Goods.FullName,
'仓库ID' = d_Stock.ID, '仓库PersonCode' = d_Stock.PerSonCode, '仓库FullName' = d_Stock.FullName,
'库存数量' = sum(d_StockGoods.Num), '库存金额' = sum(d_StockGoods.Amount)
from D_Stock inner join d_StockGoods on d_StockGoods.sId = D_Stock.Id
inner join d_Goods on d_StockGoods.gID = d_Goods.ID and pId=@ID --应该是这改成pId=@ID吧,你比较的是pId,为什么要用d_Goods.Id like @ID+'%'
group by d_Goods.Id, d_Goods.PersonCode, d_Goods.FullName, d_Stock.ID, d_Stock.PerSonCode, d_Stock.FullName
go
execute test '00001'

-晴天 2011-12-16
  • 打赏
  • 举报
回复
传入参数ID 00001,得到的应该是00001的话,改这儿:
d_Goods.Id like @ID+'%'

d_Goods.Id = @ID
kyle_huang 2011-12-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 fredrickhu 的回复:]
SQL code

create procedure test
@ID varchar(50)
as
select '商品ID' = d_Goods.Id, '商品PersonCode' = d_Goods.PersonCode, '商品FullName' = d_Goods.FullName,
'仓库ID' = d_Stock.ID, '仓库PersonCode' = d_S……
[/Quote]

跟我的效果一模一样,没改变。
不行啊。
kyle_huang 2011-12-16
  • 打赏
  • 举报
回复
请问?[Quote=引用 4 楼 jiangzhong610 的回复:]
引用 3 楼 fredrickhu 的回复:

SQL code
create procedure test
@ID varchar(50)
as
select '商品ID' = d_Goods.Id, '商品PersonCode' = d_Goods.PersonCode, '商品FullName' = d_Goods.FullName,
'仓库ID' = d_Stock.ID, ……
[/Quote]
kyle_huang 2011-12-16
  • 打赏
  • 举报
回复
谢谢,但是按你那个方法的话00001,是不出现任何数据的。[Quote=引用 1 楼 qianjin036a 的回复:]
传入参数ID 00001,得到的应该是00001的话,改这儿:
d_Goods.Id like @ID+'%'

d_Goods.Id = @ID
[/Quote]
jiangzhong610 2011-12-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 fredrickhu 的回复:]

SQL code
create procedure test
@ID varchar(50)
as
select '商品ID' = d_Goods.Id, '商品PersonCode' = d_Goods.PersonCode, '商品FullName' = d_Goods.FullName,
'仓库ID' = d_Stock.ID, '仓库PersonCode' = d_Stock.……
[/Quote].
目 录 摘要…………………………………………………………………………1 Abstract……………………………………………………………………2 1. 绪论………………………………………………………………3 1. 1管理信息系统的概述………………………………………………………3 1. 2数据库应用系统开发简介…………………………………………………3 1. 3库存管理系统………………………………………………………………5 1.3.1国内外同类管理软件的研究现状与发展趋势………………………………… 5 1.3.2库存管理系统研究背景与意义……………………………………………………6 第二章 数据库理论基础……………………………………………………7 2.1数据库系统设计………………………………………………………………7 2.2SQL语言介绍…………………………………………………………………7 2.2.1SQL基础……………………………………………………………………………7 2.2.2SQL语句……………………………………………………………………………8 第三章 应用系统开发工具……………………………………………… 9 3.1Visual Basic简介及实现原理…………………………………………………9 3.2数据库组件介绍………………………………………………………………9 3.3SQL语言在VB中的应用…………………………………………………… 10 3.4Access2000简述………………………………………………………………11 4. 库存管理系统设计分析…………………………………………12 4.1需求分析………………………………………………………………………12 4.2模块划分………………………………………………………………………13 4.3数据库设计……………………………………………………………………15 5. 应用程序设计……………………………………………………18 5.1程序结构……………………………………………………………………18 5.2程序源代码…………………………………………………………………19 第六章 设计总结……………………………………………………… 38 参考文献……………………………………………………………………39 摘要 随着现代工业的发展,计算机信息管理系统越来越受到企业重视。本文主要分析了库存 管理系统的一些基本功能和组成情况,包括系统的需求分析、系统结构,功能模块划分 以及数据库模式分析等,重点对应用程序的实际开发实现作了介绍。达到了数据的一致 性和安全性,且应用程序功能完备,符合了库存管理系统作为典型的信息管理系统(MIS )的要求。同时简单介绍了Visual Basic编程环境和Access数据库管理系统的功能特点,库存管理系统是企业物流管理中不 可或缺的一部分。 关键词:库存管理,数据库,信息管理,VB Abstract With the development of modern industry, the information management system of the computer is being paid attention to by enterprises. This text has analysed some basic functions of the administrative system of the stock and makes up the situation mainly, including the systematic demand is analysed, systematic structure, the function module divides and the data base mode is analysed etc., have realized doing the introduction to the actual development of the application program especially. Having reached the consistency and security of the data, and the application program function is complete, have accorded with the administrative system of the stock as the request for the typical information management system (MIS). Introduced the function c
目 录 摘要…………………………………………………………………………1 Abstract……………………………………………………………………2 1. 绪论………………………………………………………………3 1. 1管理信息系统的概述………………………………………………………3 1. 2数据库应用系统开发简介…………………………………………………3 1. 3库存管理系统………………………………………………………………5 1.3.1国内外同类管理软件的研究现状与发展趋势………………………………… 5 1。3。2库存管理系统研究背景与意义……………………………………………………6 第二章 数据库理论基础……………………………………………………7 2.1数据库系统设计………………………………………………………………7 2。2SQL语言介绍…………………………………………………………………7 2.2.1SQL基础……………………………………………………………………………7 2.2.2SQL语句……………………………………………………………………………8 第三章 应用系统开发工具……………………………………………… 9 3。1Visual Basic简介及实现原理…………………………………………………9 3。2数据库组件介绍………………………………………………………………9 3.3SQL语言在VB中的应用…………………………………………………… 10 3。4Access2000简述………………………………………………………………11 4. 库存管理系统设计分析…………………………………………12 4。1需求分析………………………………………………………………………12 4。2模块划分………………………………………………………………………13 4。3数据库设计……………………………………………………………………15 5. 应用程序设计……………………………………………………18 5。1程序结构……………………………………………………………………18 5。2程序源代码…………………………………………………………………19 第六章 设计总结……………………………………………………… 38 参考文献……………………………………………………………………39 摘要 随着现代工业的发展,计算机信息管理系统越来越受到企业重视。本文主要分析了库存 管理系统的一些基本功能和组成情况,包括系统的需求分析、系统结构,功能模块划分以 及数据库模式分析等,重点对应用程序的实际开发实现作了介绍。达到了数据的一致性和 安全性,且应用程序功能完备,符合了库存管理系统作为典型的信息管理系统(MIS)的 要求.同时简单介绍了Visual Basic编程环境和Access数据库管理系统的功能特点,库存管理系统是企业物流管理中不 可或缺的一部分。 关键词:库存管理,数据库,信息管理,VB Abstract With the development of modern industry, the information management system of the computer is being paid attention to by enterprises。 This text has analysed some basic functions of the administrative system of the stock and makes up the situation mainly, including the systematic demand is analysed, systematic structure, the function module divides and the data base mode is analysed etc。, have realized doing the introduction to the actual development of the application program especially。 Having reached the consistency and security of the data, and the application program function is complete, have accorded with the administrative system of the stock as the request for the typical information management system (MIS). Introduced the function c
目 录 摘要………………………………………………………………………………………3 1 引言……………………………………………………………………………………4 1.1 开发背景与现状………………………………………………………………4 1.2 开发设计的意义………………………………………………………………4 1.3 开发工具………………………………………………………………………4 1.3.1 Visual studio.NET 2008简介…………………………………………………4 1.3.2 SQL Server 2005简介………………………………………………………5 2 系统分析 ……………………………………………………………………………6 2.1 可行性分析…………………………………………………………………… 6 2.2 系统需求分析………………………………………………………………… 6 2.3 系统数据流图………………………………………………………………… 8 3 总体设计 ……………………………………………………………………………8 3.1 系统设计目标………………………………………………………………… 8 3.2 系统总体功能 ………………………………………………………………… 9 3.3 系统结构图…………………………………………………………………… 10 4 详细设计…………………………………………………………………………… 11 4.1 数据库设计…………………………………………………………………… 11 4.1.1 数据库的引入. .………………………………………………………………11 4.1.2 数据库逻辑结构设计E-R图…………………………………………………12 4.1.3数据库逻辑结构………………………………………………………………13 4.2 模块设计…………………………………………………………………………14 4.2.1 客户模块设计………………………………………………………………14 5 编码、实现与测试………………………………………………………………… 18 5.1 数据库连接…………………………………………………………………… 18 5.2 系统实现……………………………………………………………………… 18 5.3 系统测试……………………………………………………………………… 18 6 开发总结……………………………………………………………………………19 7 致谢…………………………………………………………………………………20 8 参考文献……………………………………………………………………………20

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧