2

我有一个名为的表Bowzer,其中有一列名为Type.

当我尝试运行此查询时,SSMS 无法识别该列Type

这是我的查询

update Bowzer
set inserted_by = ISNULL(inserted_by, 'Auto')
where (bowzer_id = 8 and inserted_by is null and type='CRUDE')

在这里它无法识别列Type并给出错误

列名类型无效

Type不允许使用此列名吗?

另外,我想检查该Inserted_By列是否为空,然后将其替换为一个值Auto

我怎么做?

编辑 - 表 Bowzer 的 1 个 DDL

CREATE TABLE [dbo].[Bowzer](
    [bowzer_id] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
    [bowzer_no] [nvarchar](20) NULL,
    [quantity] [numeric](18, 0) NULL,
    [dip1] [numeric](18, 0) NULL,
    [Cmpt_Capacity1] [numeric](5, 0) NULL,
    [dip2] [numeric](18, 0) NULL,
    [Cmpt_Capacity2] [numeric](5, 0) NULL,
    [dip3] [numeric](18, 0) NULL,
    [Cmpt_Capacity3] [numeric](5, 0) NULL,
    [dip4] [numeric](18, 0) NULL,
    [Cmpt_Capacity4] [numeric](5, 0) NULL,
    [dip5] [numeric](18, 0) NULL,
    [Cmpt_Capacity5] [numeric](5, 0) NULL,
    [expiry_date] [datetime] NOT NULL,
    [status] [bit] NOT NULL,
    [inserted_on] [datetime] NULL,
    [inserted_by] [nvarchar](20) NULL,
    [Type] [nvarchar](50) NULL,
 CONSTRAINT [PK_Bowzer] PRIMARY KEY CLUSTERED 
(
    [bowzer_id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
4

2 回答 2

4

试试这个

update Bowzer
set inserted_by = ISNULL(inserted_by, 'Auto')
where (bowzer_id = 8 and inserted_by is null and [type]='CRUDE')
于 2012-06-14T05:07:40.010 回答
1

检查是否为空,用例

Update Bowzer set inserted_by  = Case When inserted_by IS NULL THEN 'Auto' Else inserted_by End
where (bowzer_id = 8 and inserted_by is null and [type]='CRUDE')
于 2012-06-14T05:11:30.887 回答