在sql中,可不可以用select语句取出某个列,并将该列赋值给一个变量

来源:百度知道 编辑:UC知道 时间:2024/05/17 02:41:07
如果可以的话,该怎么写这条语句

使用存储过程就可以!
CREATE PROCEDURE [dbo].[d_hotelsLogin]
@ID decimal =0 output,
@userID varchar(50),
@pwd varchar(50),
@log_ip varchar(50)
AS
begin
if not exists(select * from dbo.[hotels] where userID=@userID and pwd=@pwd)
begin
return 0
end
else
begin
select @ID = id from dbo.[hotels] where userID=@userID and pwd=@pwd
update dbo.[hotels] set log_time=getDate(),log_count=log_count+1,log_ip=@log_ip where id=@ID and dateDiff(d,log_time,getDate())<>0
return 1
end
end
GO

这有什么问题么 ..?

一般的 SQL 查询不都是用一条 SELECT 语句之后把结果赋给 RecordSet ...?

insert into 表名 (列名) values ('值')