插入包含单个动态数据的多行
我正在尝试将具有不同 @EmpId
的多行的相同数据插入表中。
追问:
CREATE PROCEDURE usp_SaveEmployee
(@EmpIds varchar(50), //1,2,3,4
@StateId int,
@CountryId int,
@Comments varchar(50))
AS
BEGIN
INSERT INTO dbo.tblEmpDetails (EmpId, StateId, CountryId, Comments)
SELECT *
FROM [dbo].[FN_ListToTable] (',',@EmpIds)
-- How can I add this: (@StateId, @CountryId, @Comments)
END
或者还有其他更好的方法来处理这个问题吗?
I'm trying to insert same data for multiple rows with different @EmpId
into table.
Query:
CREATE PROCEDURE usp_SaveEmployee
(@EmpIds varchar(50), //1,2,3,4
@StateId int,
@CountryId int,
@Comments varchar(50))
AS
BEGIN
INSERT INTO dbo.tblEmpDetails (EmpId, StateId, CountryId, Comments)
SELECT *
FROM [dbo].[FN_ListToTable] (',',@EmpIds)
-- How can I add this: (@StateId, @CountryId, @Comments)
END
Or is there any other better way to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在选择列表中定义正确的列即可:
另请注意,SQL Server 有一个内置的string_split() 函数。
Simply define the correct columns in the select list:
Also note that SQL Server has a built-in string_split() function.