在sql server 2008中将变量定义为scope_identity的问题 [英] problem in defining a variable as scope_identity in sql server 2008
本文介绍了在sql server 2008中将变量定义为scope_identity的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在将标量变量声明为范围标识时面临问题。这个存储过程有什么问题。
ALTER程序[dbo]。[spuserdetails]
@Name varchar(50),
@DOB datetime,
@Age int = null,
@ Address1 varchar(70),
@phone int,
@Country varchar(50)= null,
@States Varchar( 50)= null,
@City varchar(50)= null,
@E_ID int Out
set @E_ID = SCOPE_IDENTITY()
As
Begin
插入userdetails(Name,DOB,Addr,phn,Country,States,City)
values(@ Name,@ DOB,@ Address1,@ phone,@ Country,@ States,@ City)
从userdetails中选择E_ID
结束
我想要做的是当用户从我的asp.net网络应用程序向数据库输入任何信息时。
此处自动生成的标识列我的Web应用程序屏幕上显示E_ID弹出祝贺你的Empid是< that identity =col。=value =>
解决方案
你可以用这种方式声明它.... :)
INSERT INTO [dbo]。[shopw_users]
([generalids],[username],[email],[password] ,[allowedips],[realname],[姓名缩写],[销售人员],[ccaccess],[timemade],[defaultshop],[dailystat])
VALUES
( @ generalids , @ username , @email , @ password , @ allowedips , @realname , @ initials , @ salesperson , @ ccaccess , @ timemade , @ defaultshop , @ dailystat )
SET @ Ou tput = CAST( @@ IDENTITY AS [ nvarchar ](max))
我已经纠正了Sp ..我希望它有效。
ALTER procedure [dbo]。[spuserdetails]
@ Name varchar (< span class =code-digit> 50 ),
@ DOB datetime ,
@ Age int = null,
@ Address1 varchar ( 70 ),
@ phone < span class =code-keyword> int ,
@ Country varchar ( 50 )= null ,
@ States Varchar ( 50 )= null ,
@ City varchar ( 50 )= null
作为
开始
插入 进入 userdetails(Name,DOB,Addr,phn ,国家,州,市)
值( @ Name , @ DOB , @ Address1 , @ phone , @ Country , @ States , @ City )
- set @E_ID = SCOPE_IDENTITY() - set @E_ID = @@ IDENTITY
选择 SCOPE_IDENTITY ()
端跨度>
i m facing problem in declaring my scalar variable as scope identity. what is wrong with this Stored procedure.
ALTER procedure [dbo].[spuserdetails] @Name varchar(50), @DOB datetime, @Age int=null, @Address1 varchar(70), @phone int, @Country varchar(50) = null, @States Varchar(50) = null, @City varchar(50) = null, @E_ID int Out set @E_ID = SCOPE_IDENTITY() As Begin insert into userdetails(Name,DOB,Addr,phn,Country,States,City ) values (@Name,@DOB , @Address1 , @phone , @Country, @States, @City ) select E_ID from userdetails end
what i want to do is when user enters any information into the database from my asp.net web app.
the autogeneted identity column here E_ID popup on my web application screen that "Congrats your Empid is <that identity="" col.="" value="">
解决方案
You can declare it by this way....:)
INSERT INTO [dbo].[shopw_users] ([generalids], [username], [email], [password], [allowedips], [realname], [initials], [salesperson], [ccaccess], [timemade], [defaultshop], [dailystat]) VALUES (@generalids, @username, @email, @password, @allowedips, @realname, @initials, @salesperson, @ccaccess, @timemade, @defaultshop, @dailystat) SET @Output = CAST(@@IDENTITY AS [nvarchar] (max))
Hi,
I have corrected the Sp.. I hope it works.
AALTER procedure [dbo].[spuserdetails] @Name varchar(50), @DOB datetime, @Age int=null, @Address1 varchar(70), @phone int, @Country varchar(50) = null, @States Varchar(50) = null, @City varchar(50) = null As Begin insert into userdetails(Name,DOB,Addr,phn,Country,States,City ) values (@Name,@DOB , @Address1 , @phone , @Country, @States, @City ) --set @E_ID = SCOPE_IDENTITY()-- set @E_ID = @@IDENTITY select SCOPE_IDENTITY() end
这篇关于在sql server 2008中将变量定义为scope_identity的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文