更新列信息
Update column information
我正在尝试将 Mgrstat 列中的信息更新为 3,并希望批量输入信息。事实上,我必须使用“=”并分别输入每个 AppID,但我宁愿一次输入多个。下面的查询显示了我使用 "in" 的尝试,但也没有用。我得到 "Incorrect syntax near the keword 'in'".
有什么想法吗?谢谢大家!
declare @appid as int
declare @mgrstat as int
set @appid in ('10995',
'11201',
'9523',
'9558',
'9666',
'10069',
'10547',
'10548',
'9702',
'10698',
'9754',
'10161',
'10162',
'11240',
'11241',
'9553',
'10848',
'10667',
'9383',
'10709',
'9696',
'10053',
'10702')
set @mgrstat = 3
update [Compensation].[dbo].[dev_RPT_Approval]
set Mgr_Stat = @mgrstat
FROM [Compensation].[dbo].[dev_RPT_Approval]
where @appid = App_Id
select *
from [Compensation].[dbo].[dev_RPT_Approval]
where @appid = App_Id
如果我理解正确,并且您希望所有 mgr_stats
都为 3,其中 app_id 在您的问题中提供的列表中,那么您可以通过几种方式做到这一点:
update [Compensation].[dbo].[dev_RPT_Approval]
set Mgr_Stat = 3
where app_id in (
'10995',
'11201',
'9523',
'9558',
'9666',
'10069',
'10547',
'10548',
'9702',
'10698',
'9754',
'10161',
'10162',
'11240',
'11241',
'9553',
'10848',
'10667',
'9383',
'10709',
'9696',
'10053',
'10702'
)
或(sql 服务器使用 table 变量)
declare @ids table (id varchar(50))
insert into @ids (id)
select '10995'
union all select '11201'
union all select '9523'
union all select '9558'
union all select '9666'
union all select '10069'
union all select '10547'
union all select '10548'
union all select '9702'
union all select '10698'
union all select '9754'
union all select '10161'
union all select '10162'
union all select '11240'
union all select '11241'
union all select '9553'
union all select '10848'
union all select '10667'
union all select '9383'
union all select '10709'
union all select '9696'
union all select '10053'
union all select '10702'
update [Compensation].[dbo].[dev_RPT_Approval]
set Mgr_Stat = 3
from [Compensation].[dbo].[dev_RPT_Approval] t
inner join @ids i on t.app_id = i.id
关于您发布的代码的一些注意事项:
declare @appid as int
set @appId in ...
关于这个的一些事情 - @appId 被声明为一个整数,这意味着它是一个标量值(不能是一个集合) - 对于值集合,你可以像我一样使用 table 变量在我如何完成你的问题的第二个例子中。
另外,因为你的变量是 int,我假设你的 ID 是 int 类型,不需要引号。
而不是:
where app_id in (
'10995',
....
)
你可以做到:
where app_id in (
10995,
....
)
这是您需要的SQL:
update dev_RPT_Approval set Mgr_Stat=3
where designation
in ('10995',
'11201',
'9523',
'9558',
'9666',
'10069',
'10547',
'10548',
'9702',
'10698',
'9754',
'10161',
'10162',
'11240',
'11241',
'9553',
'10848',
'10667',
'9383',
'10709',
'9696',
'10053',
'10702')
你能试试这个吗?
可能对你有用,伙计。此处您使用“=”而不是“IN”
传递多个值
update [Compensation].[dbo].[dev_RPT_Approval]
set Mgr_Stat = @mgrstat
FROM [Compensation].[dbo].[dev_RPT_Approval]
where App_Id IN(@appid)
我正在尝试将 Mgrstat 列中的信息更新为 3,并希望批量输入信息。事实上,我必须使用“=”并分别输入每个 AppID,但我宁愿一次输入多个。下面的查询显示了我使用 "in" 的尝试,但也没有用。我得到 "Incorrect syntax near the keword 'in'".
有什么想法吗?谢谢大家!
declare @appid as int
declare @mgrstat as int
set @appid in ('10995',
'11201',
'9523',
'9558',
'9666',
'10069',
'10547',
'10548',
'9702',
'10698',
'9754',
'10161',
'10162',
'11240',
'11241',
'9553',
'10848',
'10667',
'9383',
'10709',
'9696',
'10053',
'10702')
set @mgrstat = 3
update [Compensation].[dbo].[dev_RPT_Approval]
set Mgr_Stat = @mgrstat
FROM [Compensation].[dbo].[dev_RPT_Approval]
where @appid = App_Id
select *
from [Compensation].[dbo].[dev_RPT_Approval]
where @appid = App_Id
如果我理解正确,并且您希望所有 mgr_stats
都为 3,其中 app_id 在您的问题中提供的列表中,那么您可以通过几种方式做到这一点:
update [Compensation].[dbo].[dev_RPT_Approval]
set Mgr_Stat = 3
where app_id in (
'10995',
'11201',
'9523',
'9558',
'9666',
'10069',
'10547',
'10548',
'9702',
'10698',
'9754',
'10161',
'10162',
'11240',
'11241',
'9553',
'10848',
'10667',
'9383',
'10709',
'9696',
'10053',
'10702'
)
或(sql 服务器使用 table 变量)
declare @ids table (id varchar(50))
insert into @ids (id)
select '10995'
union all select '11201'
union all select '9523'
union all select '9558'
union all select '9666'
union all select '10069'
union all select '10547'
union all select '10548'
union all select '9702'
union all select '10698'
union all select '9754'
union all select '10161'
union all select '10162'
union all select '11240'
union all select '11241'
union all select '9553'
union all select '10848'
union all select '10667'
union all select '9383'
union all select '10709'
union all select '9696'
union all select '10053'
union all select '10702'
update [Compensation].[dbo].[dev_RPT_Approval]
set Mgr_Stat = 3
from [Compensation].[dbo].[dev_RPT_Approval] t
inner join @ids i on t.app_id = i.id
关于您发布的代码的一些注意事项:
declare @appid as int
set @appId in ...
关于这个的一些事情 - @appId 被声明为一个整数,这意味着它是一个标量值(不能是一个集合) - 对于值集合,你可以像我一样使用 table 变量在我如何完成你的问题的第二个例子中。
另外,因为你的变量是 int,我假设你的 ID 是 int 类型,不需要引号。
而不是:
where app_id in (
'10995',
....
)
你可以做到:
where app_id in (
10995,
....
)
这是您需要的SQL:
update dev_RPT_Approval set Mgr_Stat=3
where designation
in ('10995',
'11201',
'9523',
'9558',
'9666',
'10069',
'10547',
'10548',
'9702',
'10698',
'9754',
'10161',
'10162',
'11240',
'11241',
'9553',
'10848',
'10667',
'9383',
'10709',
'9696',
'10053',
'10702')
你能试试这个吗? 可能对你有用,伙计。此处您使用“=”而不是“IN”
传递多个值 update [Compensation].[dbo].[dev_RPT_Approval]
set Mgr_Stat = @mgrstat
FROM [Compensation].[dbo].[dev_RPT_Approval]
where App_Id IN(@appid)