存储过程问题!
时间:2011-11-17
来源:互联网
set QUOTED_IDENTIFIER ON
go
ALTER procedure [dbo].[cp]
as
declare @testn1 int
declare @testn2 int
begin
create table nocp(学号 int,姓名 char(8),testn1 int,testn2 int)
select row_number() over (order by @testn1 desc) as '名次',学号,姓名,testn1 into www from 地理 order by 学号
select row_number() over (order by @testn2 desc) as '名次',学号,姓名,testn2 into www2 from 地理 order by 学号
insert into nocp(学号,姓名,testn1,testn2) select www.学号,www.姓名,www.名次,www2.名次 from www,www2
end
分析的结果是:
命令已成功完成。
执行的结果是:
消息 208,级别 16,状态 6,过程 cp,第 15 行
对象名 'dbo.cp' 无效。
为什么不行!
作者: iamqdxy 发布时间: 2011-11-17
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go Create procedure [dbo].[cp] as declare @testn1 int declare @testn2 int begin create table nocp(学号 int,姓名 char(8),testn1 int,testn2 int) select row_number() over (order by @testn1 desc) as '名次',学号,姓名,testn1 into www from 地理 order by 学号 select row_number() over (order by @testn2 desc) as '名次',学号,姓名,testn2 into www2 from 地理 order by 学号 insert into nocp(学号,姓名,testn1,testn2) select www.学号,www.姓名,www.名次,www2.名次 from www,www2 end
作者: roy_88 发布时间: 2011-11-17
改為創建
作者: roy_88 发布时间: 2011-11-17
作者: geniuswjt 发布时间: 2011-11-17
分析的结果是:
命令已成功完成。
应该是你执行的语句不对吧?或者切过库忘了切回来了?
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER procedure [dbo].[cp]
as
declare @testn1 int
declare @testn2 int
begin
create table nocp(学号 int,姓名 char(8),testn1 int,testn2 int)
……
作者: geniuswjt 发布时间: 2011-11-17
SQL code
Create procedure [dbo].[cp] as declare @testn1 int declare @testn2 int begin create table nocp(学号 int,姓名 char(8),testn1 int,testn2 int) select row_number() over (order by @testn1 desc) as '名次',学号,姓名,testn1 into www from 地理 order by 学号 select row_number() over (order by @testn2 desc) as '名次',学号,姓名,testn2 into www2 from 地理 order by 学号 insert into nocp(学号,姓名,testn1,testn2) select www.学号, www.姓名, www.名次, www2.名次 from www,www2 WHERE www.学号=www2.学号 end
作者: roy_88 发布时间: 2011-11-17
declare @testn1 int
declare @testn2 int
是干什么用的?
没赋值,查询语句又在用.........
如果是参数的话,要写在as前面,且不要用declare,如果是程序里用的话,写在begin后面,而且要赋值.
作者: qianjin036a 发布时间: 2011-11-17
作者: qianjin036a 发布时间: 2011-11-17
作者: iamqdxy 发布时间: 2011-11-17
SQL code
Create procedure [dbo].[cp] as BEGIN IF OBJECT_ID('nocp') IS NULL create table nocp(学号 int,姓名 char(8),testn1 int,testn2 int) select row_number() over (order by testn1 desc) as '名次',学号,姓名,testn1 into www from 地理 order by 学号 select row_number() over (order by testn2 desc) as '名次',学号,姓名,testn2 into www2 from 地理 order by 学号 insert into nocp(学号,姓名,testn1,testn2) select www.学号, www.姓名, www.名次, www2.名次 from www,www2 WHERE www.学号=www2.学号 end
作者: roy_88 发布时间: 2011-11-17
执行成功,为什么数据库里没有表nocp?
存儲過程問題多多,建表最好不要放在存儲過程里
作者: roy_88 发布时间: 2011-11-17
set QUOTED_IDENTIFIER ON
go
create procedure [dbo].[cp]
@tbl varchar(8),
@testn1 varchar(8),
@testn2 varchar(8)
as
begin
create table nocp(学号 int,姓名 char(8),testn1 int,testn2 int)
select row_number() over (order by @testn1 desc) as '名次',学号,姓名,testn1 into www from @tbl order by 学号
select row_number() over (order by @testn2 desc) as '名次',学号,姓名,testn2 into www2 from @tbl order by 学号
insert into nocp(学号,姓名,testn1,testn2) select www.学号,www.姓名,www.名次,www2.名次 from www,www2
end
消息 1087,级别 15,状态 2,过程 cp,第 14 行
必须声明表变量 "@tbl"。
消息 1087,级别 15,状态 2,过程 cp,第 15 行
必须声明表变量 "@tbl"。
作者: iamqdxy 发布时间: 2011-11-17
作者: iamqdxy 发布时间: 2011-11-17
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28