AVAILABLE_STOCK有几条记录呀?多对一的话,你要怎么赋值?
解决方案 »
- 自动增加
- access数据导入SQL Server提示错误:服务器: 消息 7403, 未能找到 OLE DB 提供程序 'Provider=Microsoft.Jet.OLEDB.4.0' 的注册表项。
- SQL 错误提示语句怎么写
- access里的sql语句转换为sql server的sql语句的问题
- 求一个查询特定行的sql
- 几个查询的区别?
- 怎样消除表中的重复记录?
- 如何在mssqlserver中实现csv与access的对导
- help ! 这个统计应该怎么写 ???
- 关于用VB+SQLSERVER编程的一系列问题!!!!
- Trigger有没办法弹出一个提示信息,然后数据仍可保存?
- 如何造日期列
declare @a int
declare @b int
set @a=-3
select @b=case when @a<0 then 0 else @a end
select @b as value/*
value
0
*/--你这样不行吗??
declare @AVAILABLE_STOCK int
select
@AVAILABLE_STOCK=
(case
when AVAILABLE_STOCK<0
then 0
else AVAILABLE_STOCK
end) from Table where ... --要限定一条记录
if object_id('[lsxf1988_Table]') is not null drop table [lsxf1988_Table]
create table [lsxf1988_Table]([AVAILABLE_STOCK] int)
insert [lsxf1988_Table]
select -1 union all
select 9 union all
select 8declare @AVAILABLE_STOCK int
set @AVAILABLE_STOCK=( select top 1
case when AVAILABLE_STOCK<0 then 0
else AVAILABLE_STOCK end from [lsxf1988_Table])select @AVAILABLE_STOCK as [库存]
/*
库存
-----------
0
*/多个值的时候可以使用top 1赋值的同时不能起别名。
case when AVAILABLE_STOCK<0 then 0
else AVAILABLE_STOCK end from TABLE)
as [库存]
消息 156,级别 15,状态 1,第 24 行
关键字 'as' 附近有语法错误。报这错?
消息 141,级别 15,状态 1,第 3 行
向变量赋值的 SELECT 语句不能与数据检索操作结合使用。
if object_id('[lsxf1988_Table]') is not null drop table [lsxf1988_Table]
create table [lsxf1988_Table]([AVAILABLE_STOCK] int)
insert [lsxf1988_Table] select -9 declare @AVAILABLE_STOCK int
select
@AVAILABLE_STOCK=
(case
when AVAILABLE_STOCK<0
then 0
else AVAILABLE_STOCK
end)
from [lsxf1988_Table]select @AVAILABLE_STOCK as 库存
这样是没有问题的。
if object_id('[lsxf1988_Table]') is not null drop table [lsxf1988_Table]
create table [lsxf1988_Table]([AVAILABLE_STOCK] int)
insert [lsxf1988_Table] select -9 declare @AVAILABLE_STOCK int
select @AVAILABLE_STOCK,
@AVAILABLE_STOCK=
(case
when AVAILABLE_STOCK<0
then 0
else AVAILABLE_STOCK
end)
from [lsxf1988_Table]select @AVAILABLE_STOCK as 库存
--A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.
这样就会报错了,赋值的同时不要直接查询
select
@AVAILABLE_STOCK=
(case
when AVAILABLE_STOCK<0
then 0
else AVAILABLE_STOCK
end)
as [库存] from Table
看这个语句意思是,如果为负数就赋值为0,否则就是原值
这样的话
用绝对值函数试试,(AVAILABLE_STOCK + abs(AVAILABLE_STOCK))/2赋值给@AVAILABLE_STOCK
select
@AVAILABLE_STOCK= @AVAILABLE_STOCK+
(case
when AVAILABLE_STOCK<0
then 0
else AVAILABLE_STOCK
end)
as [库存] from Table如果你查询的类型不一致,需要自己转换类型