sql server中的一个问题 [英] a problem in sql server

查看:55
本文介绍了sql server中的一个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我在sql server中遇到了问题。

我创建了一个表,并在另一个存储过程中创建了一个存储过程。

当我执行USP_CRE_USP_INS时,sqlserver给我一个错误。

请帮帮我



Hello guys. I have a problem in sql server .
I create a table and I create a stored proc in another stored proc.
When i execute USP_CRE_USP_INS the sqlserver give me an error.
please help me

CREATE DATABASE TESTDB
GO
CREATE TABLE TEST
(
   ID INT IDENTITY PRIMARY KEY,
   FNAME VARCHAR(50),
   LNAME VARCHAR (50)
)
GO
CREATE PROC USP_CRE_USP_INS
AS
BEGIN
     DECLARE @RESULT VARCHAR(500)
     SET @RESULT=
        ''CREATE PROC USP_INS_TEST
         @FNAME VARCHAR(50),
         @LNAME VARCHAR(50)
         AS
         BEGIN
         INSERT TEST(FNAME,LNAME)
         VALUES (@FNAME,@LNAME)
         END  ''
     EXEC @RESULT ''123'',''123''
END





和sql server错误是:





And sql server error is:

Msg 203, Level 16, State 2, Procedure USP_CRE_USP_INS, Line 14
The name ''CREATE PROC USP_INS_TEST
         @FNAME VARCHAR(50),
         @LNAME VARCHAR(50)
         AS
         BEGIN
         INSERT TEST(FNAME,LNAME)
         VALUES (@FNAME,@LNAME)
         END  '' is not a valid identifier.

推荐答案

我相信你需要用括号括起来 - EXEC(@RESULT''123'',''123'')
I believe you need to surround it with parentheses -- EXEC ( @RESULT ''123'',''123'' )


查看你的存储这里的程序是一些建议。

如果你想在存储过程中执行另一个存储过程(SP),你就是这样做的。

Looking at your stored procedure here are some suggestions.
If you want to execute another stored procedure(SP) inside a stored procedure this is how you would do it
EXEC USP_INS_TEST '123','123'



说到那里不需要存储过程USP_CRE_USP_INS,因为它只是尝试执行st ored程序USP_INS_TEST,该SP中没有其他SQL命令。所以你可以直接调用SP USP_INS_TEST而不是调用SP USP_CRE_USP_INS。



SP =存储过程。


Having said that there is no necessity of the stored procedure USP_CRE_USP_INS as it is just trying to execute the stored procedure USP_INS_TEST and there are no other SQL commands in that SP. So you can just directly call the SP USP_INS_TEST instead of calling SP USP_CRE_USP_INS.

SP = Stored Procedure.


这篇关于sql server中的一个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆