AS insert into products(chrproductname,txtdescription,chrproductimage,intprice,intactive) values(@chrproductname,@txtdescription,@chrproductimage,@intprice,@intactive)select @@idproduct=idproduct from products where chrproductname=@chrproductname, txtdescription=@txtdescription, chrproductimage=@chrproductimage, intprice=@intprice, intactive=@intactive 系统认为where 后面有问题 。另:@@idproduct和idproduct 都是int型
这个问题用select @@identity as 'id'解决了。现在的问题是:用存储过程插入时,字符型的数据不能完整的插入到库中。(存储过程如下:) CREATE PROCEDURE sp_insertproduct @chrproductname varchar, @txtdescription text, @chrproductimage varchar, @intprice int, @intactive int AS insert into products(chrproductname,txtdescription,chrproductimage,intprice,intactive) values(@chrproductname,@txtdescription,@chrproductimage,@intprice,@intactive) 例如:@chrproductname=='shoes',但擦入到表中的却是:'s' 怎么解决呢?
as
......
select @var_out = id from XX where XXX
go
http://www.csdn.net/Expert/FAQ/FAQ_Index.asp?id=858
或用
SELECT SCOPE_IDENTITY()
或用
SELECT IDENT_CURRENT('news')
ID列不一定是IDENTITY
估计楼主是这个意思吧,要不插入时必须提供ID的值,那样就没有这一问了,因为插入前就知道。
我是想向商品表中放入新的商品,在浏览者看来在填写完新商品,按下回车键就把现有的商品列表全读出来了(当然也包括刚插入的那个)。
我是想向商品表中放入新的商品,在浏览者看来在填写完新商品,按下回车键就把现有的商品列表全读出来了(当然也包括刚插入的那个)。
sql="execute sp_insertproduct '" &chrproductname & "','" &txtdescription &"','" &chrproductimage &"',"&intprice &","&intactive & ";select @@identity as 'id'"
set rsproduct=dbproduct.execute(sql)
set rsproduct=rsproduct.nextrecordset
(sp_insertproduct就是该存储过程)
但现在还有个问题:插入的chrproductname 等varchar类型的
字段之插入了第一个字母。
AS
SELECT 'Title Name' = title
FROM titles
WHERE title LIKE @@TITLE
SELECT @@SUM = SUM(price)
FROM titles
WHERE title LIKE @@TITLE
GO接下来,将该 OUTPUT 参数用于控制流语言。 说明 OUTPUT 变量必须在创建表和使用该变量时都进行定义。
参数名和变量名不一定要匹配,不过数据类型和参数位置必须匹配(除非使用 @@SUM = variable 形式)。 DECLARE @@TOTALCOST money
EXECUTE titles_sum 'The%', @@TOTALCOST OUTPUT这是我在帮助里考的例子,绝对没错。
你插入的字段值定义的是什么类型?是不是要进行UNICODE转换。
@txtdescription text,
@chrproductimage varchar,
@intprice int,
@intactive int,
@@idproduct int output
AS
insert into products(chrproductname,txtdescription,chrproductimage,intprice,intactive)
values(@chrproductname,@txtdescription,@chrproductimage,@intprice,@intactive)select @@idproduct=idproduct from products
where chrproductname=@chrproductname,
txtdescription=@txtdescription,
chrproductimage=@chrproductimage,
intprice=@intprice,
intactive=@intactive
系统认为where 后面有问题 。另:@@idproduct和idproduct 都是int型
CREATE PROCEDURE sp_insertproduct @chrproductname varchar,
@txtdescription text,
@chrproductimage varchar,
@intprice int,
@intactive int
AS
insert into products(chrproductname,txtdescription,chrproductimage,intprice,intactive)
values(@chrproductname,@txtdescription,@chrproductimage,@intprice,@intactive)
例如:@chrproductname=='shoes',但擦入到表中的却是:'s'
怎么解决呢?
查查看products.chrproductname的寬度是多少? 看是不是char(1)?
@chrproductname varchar 就是varchar(1)了
@@idproduct int output 改为 @idno
@@变量不能输出。